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)
59 #define SVGA_BUFFER_USAGE_SHADER (1 << 2)
62 * Relocation flags to help with dirty tracking
63 * SVGA_RELOC_WRITE - The command will cause a GPU write to this
65 * SVGA_RELOC_READ - The command will cause a GPU read from this
67 * SVGA_RELOC_INTERNAL The command will only transfer data internally
68 * within the resource, and optionally clear
70 * SVGA_RELOC_DMA - Only set for resource buffer DMA uploads for winsys
71 * implementations that want to track the amount
72 * of such data referenced in the command stream.
74 #define SVGA_RELOC_WRITE (1 << 0)
75 #define SVGA_RELOC_READ (1 << 1)
76 #define SVGA_RELOC_INTERNAL (1 << 2)
77 #define SVGA_RELOC_DMA (1 << 3)
79 #define SVGA_FENCE_FLAG_EXEC (1 << 0)
80 #define SVGA_FENCE_FLAG_QUERY (1 << 1)
83 /** Opaque surface handle */
84 struct svga_winsys_surface
;
87 /** Opaque guest-backed objects */
88 struct svga_winsys_gb_shader
;
93 * SVGA per-context winsys interface.
95 struct svga_winsys_context
98 (*destroy
)(struct svga_winsys_context
*swc
);
101 (*reserve
)(struct svga_winsys_context
*swc
,
102 uint32_t nr_bytes
, uint32_t nr_relocs
);
105 * Emit a relocation for a host surface.
107 * @param flags bitmask of SVGA_RELOC_* flags
109 * NOTE: Order of this call does matter. It should be the same order
110 * as relocations appear in the command buffer.
113 (*surface_relocation
)(struct svga_winsys_context
*swc
,
116 struct svga_winsys_surface
*surface
,
120 * Emit a relocation for a guest memory region.
122 * @param flags bitmask of SVGA_RELOC_* flags
124 * NOTE: Order of this call does matter. It should be the same order
125 * as relocations appear in the command buffer.
128 (*region_relocation
)(struct svga_winsys_context
*swc
,
129 struct SVGAGuestPtr
*ptr
,
130 struct svga_winsys_buffer
*buffer
,
135 * Emit a relocation for a guest-backed shader object.
137 * NOTE: Order of this call does matter. It should be the same order
138 * as relocations appear in the command buffer.
141 (*shader_relocation
)(struct svga_winsys_context
*swc
,
145 struct svga_winsys_gb_shader
*shader
);
148 * Emit a relocation for a guest-backed context.
150 * NOTE: Order of this call does matter. It should be the same order
151 * as relocations appear in the command buffer.
154 (*context_relocation
)(struct svga_winsys_context
*swc
, uint32
*cid
);
157 * Emit a relocation for a guest Memory OBject.
159 * @param flags bitmask of SVGA_RELOC_* flags
160 * @param offset_into_mob Buffer starts at this offset into the MOB.
162 * Note that not all commands accept an offset into the MOB and
163 * those commands can't use suballocated buffer pools. To trap
164 * errors from improper buffer pool usage, set the offset_into_mob
168 (*mob_relocation
)(struct svga_winsys_context
*swc
,
170 uint32
*offset_into_mob
,
171 struct svga_winsys_buffer
*buffer
,
176 (*commit
)(struct svga_winsys_context
*swc
);
179 (*flush
)(struct svga_winsys_context
*swc
,
180 struct pipe_fence_handle
**pfence
);
183 * Context ID used to fill in the commands
185 * Context IDs are arbitrary small non-negative integers,
186 * global to the entire SVGA device.
191 ** BEGIN new functions for guest-backed surfaces.
194 boolean have_gb_objects
;
197 * Map a guest-backed surface.
198 * \param flags bitmaks of PIPE_TRANSFER_x flags
200 * The surface_map() member is allowed to fail due to a
201 * shortage of command buffer space, if the
202 * PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE bit is set in flags.
203 * In that case, the caller must flush the current command
204 * buffer and reissue the map.
207 (*surface_map
)(struct svga_winsys_context
*swc
,
208 struct svga_winsys_surface
*surface
,
209 unsigned flags
, boolean
*retry
);
212 * Unmap a guest-backed surface.
213 * \param rebind returns a flag indicating whether the caller should
214 * issue a SVGA3D_BindGBSurface() call.
217 (*surface_unmap
)(struct svga_winsys_context
*swc
,
218 struct svga_winsys_surface
*surface
,
225 * SVGA per-screen winsys interface.
227 struct svga_winsys_screen
230 (*destroy
)(struct svga_winsys_screen
*sws
);
232 SVGA3dHardwareVersion
233 (*get_hw_version
)(struct svga_winsys_screen
*sws
);
236 (*get_cap
)(struct svga_winsys_screen
*sws
,
237 SVGA3dDevCapIndex index
,
238 SVGA3dDevCapResult
*result
);
241 * Create a new context.
243 * Context objects encapsulate all render state, and shader
244 * objects are per-context.
246 * Surfaces are not per-context. The same surface can be shared
247 * between multiple contexts, and surface operations can occur
250 struct svga_winsys_context
*
251 (*context_create
)(struct svga_winsys_screen
*sws
);
255 * This creates a "surface" object in the SVGA3D device,
256 * and returns the surface ID (sid). Surfaces are generic
257 * containers for host VRAM objects like textures, vertex
258 * buffers, and depth/stencil buffers.
260 * Surfaces are hierarchial:
262 * - Surface may have multiple faces (for cube maps)
264 * - Each face has a list of mipmap levels
266 * - Each mipmap image may have multiple volume
267 * slices, if the image is three dimensional.
269 * - Each slice is a 2D array of 'blocks'
271 * - Each block may be one or more pixels.
272 * (Usually 1, more for DXT or YUV formats.)
274 * Surfaces are generic host VRAM objects. The SVGA3D device
275 * may optimize surfaces according to the format they were
276 * created with, but this format does not limit the ways in
277 * which the surface may be used. For example, a depth surface
278 * can be used as a texture, or a floating point image may
279 * be used as a vertex buffer. Some surface usages may be
280 * lower performance, due to software emulation, but any
281 * usage should work with any surface.
283 struct svga_winsys_surface
*
284 (*surface_create
)(struct svga_winsys_screen
*sws
,
285 SVGA3dSurfaceFlags flags
,
286 SVGA3dSurfaceFormat format
,
289 uint32 numMipLevels
);
292 * Creates a surface from a winsys handle.
293 * Used to implement pipe_screen::resource_from_handle.
295 struct svga_winsys_surface
*
296 (*surface_from_handle
)(struct svga_winsys_screen
*sws
,
297 struct winsys_handle
*whandle
,
298 SVGA3dSurfaceFormat
*format
);
301 * Get a winsys_handle from a surface.
302 * Used to implement pipe_screen::resource_get_handle.
305 (*surface_get_handle
)(struct svga_winsys_screen
*sws
,
306 struct svga_winsys_surface
*surface
,
308 struct winsys_handle
*whandle
);
311 * Whether this surface is sitting in a validate list
314 (*surface_is_flushed
)(struct svga_winsys_screen
*sws
,
315 struct svga_winsys_surface
*surface
);
318 * Reference a SVGA3D surface object. This allows sharing of a
319 * surface between different objects.
322 (*surface_reference
)(struct svga_winsys_screen
*sws
,
323 struct svga_winsys_surface
**pdst
,
324 struct svga_winsys_surface
*src
);
327 * Buffer management. Buffer attributes are mostly fixed over its lifetime.
329 * @param usage bitmask of SVGA_BUFFER_USAGE_* flags.
331 * alignment indicates the client's alignment requirements, eg for
334 struct svga_winsys_buffer
*
335 (*buffer_create
)( struct svga_winsys_screen
*sws
,
341 * Map the entire data store of a buffer object into the client's address.
342 * usage is a bitmask of PIPE_TRANSFER_*
345 (*buffer_map
)( struct svga_winsys_screen
*sws
,
346 struct svga_winsys_buffer
*buf
,
350 (*buffer_unmap
)( struct svga_winsys_screen
*sws
,
351 struct svga_winsys_buffer
*buf
);
354 (*buffer_destroy
)( struct svga_winsys_screen
*sws
,
355 struct svga_winsys_buffer
*buf
);
359 * Reference a fence object.
362 (*fence_reference
)( struct svga_winsys_screen
*sws
,
363 struct pipe_fence_handle
**pdst
,
364 struct pipe_fence_handle
*src
);
367 * Checks whether the fence has been signalled.
368 * \param flags driver-specific meaning
369 * \return zero on success.
371 int (*fence_signalled
)( struct svga_winsys_screen
*sws
,
372 struct pipe_fence_handle
*fence
,
376 * Wait for the fence to finish.
377 * \param flags driver-specific meaning
378 * \return zero on success.
380 int (*fence_finish
)( struct svga_winsys_screen
*sws
,
381 struct pipe_fence_handle
*fence
,
386 ** BEGIN new functions for guest-backed surfaces.
389 /** Are guest-backed objects enabled? */
390 bool have_gb_objects
;
392 /** Can we do DMA with guest-backed objects enabled? */
396 * Create and define a GB shader.
398 struct svga_winsys_gb_shader
*
399 (*shader_create
)(struct svga_winsys_screen
*sws
,
400 SVGA3dShaderType type
,
401 const uint32
*bytecode
,
405 * Destroy a GB shader. It's safe to call this function even
406 * if the shader is referenced in a context's command stream.
409 (*shader_destroy
)(struct svga_winsys_screen
*sws
,
410 struct svga_winsys_gb_shader
*shader
);
415 struct svga_winsys_screen
*
416 svga_winsys_screen(struct pipe_screen
*screen
);
418 struct svga_winsys_context
*
419 svga_winsys_context(struct pipe_context
*context
);
421 struct pipe_resource
*
422 svga_screen_buffer_wrap_surface(struct pipe_screen
*screen
,
423 enum SVGA3dSurfaceFormat format
,
424 struct svga_winsys_surface
*srf
);
426 struct svga_winsys_surface
*
427 svga_screen_buffer_get_winsys_surface(struct pipe_resource
*buffer
);
429 #endif /* SVGA_WINSYS_H_ */