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)
82 #define SVGA_SURFACE_USAGE_SHARED (1 << 0)
84 /** Opaque surface handle */
85 struct svga_winsys_surface
;
88 /** Opaque guest-backed objects */
89 struct svga_winsys_gb_shader
;
94 * SVGA per-context winsys interface.
96 struct svga_winsys_context
99 (*destroy
)(struct svga_winsys_context
*swc
);
102 (*reserve
)(struct svga_winsys_context
*swc
,
103 uint32_t nr_bytes
, uint32_t nr_relocs
);
106 * Emit a relocation for a host surface.
108 * @param flags bitmask of SVGA_RELOC_* flags
110 * NOTE: Order of this call does matter. It should be the same order
111 * as relocations appear in the command buffer.
114 (*surface_relocation
)(struct svga_winsys_context
*swc
,
117 struct svga_winsys_surface
*surface
,
121 * Emit a relocation for a guest memory region.
123 * @param flags bitmask of SVGA_RELOC_* flags
125 * NOTE: Order of this call does matter. It should be the same order
126 * as relocations appear in the command buffer.
129 (*region_relocation
)(struct svga_winsys_context
*swc
,
130 struct SVGAGuestPtr
*ptr
,
131 struct svga_winsys_buffer
*buffer
,
136 * Emit a relocation for a guest-backed shader object.
138 * NOTE: Order of this call does matter. It should be the same order
139 * as relocations appear in the command buffer.
142 (*shader_relocation
)(struct svga_winsys_context
*swc
,
146 struct svga_winsys_gb_shader
*shader
);
149 * Emit a relocation for a guest-backed context.
151 * NOTE: Order of this call does matter. It should be the same order
152 * as relocations appear in the command buffer.
155 (*context_relocation
)(struct svga_winsys_context
*swc
, uint32
*cid
);
158 * Emit a relocation for a guest Memory OBject.
160 * @param flags bitmask of SVGA_RELOC_* flags
161 * @param offset_into_mob Buffer starts at this offset into the MOB.
163 * Note that not all commands accept an offset into the MOB and
164 * those commands can't use suballocated buffer pools. To trap
165 * errors from improper buffer pool usage, set the offset_into_mob
169 (*mob_relocation
)(struct svga_winsys_context
*swc
,
171 uint32
*offset_into_mob
,
172 struct svga_winsys_buffer
*buffer
,
177 (*commit
)(struct svga_winsys_context
*swc
);
180 (*flush
)(struct svga_winsys_context
*swc
,
181 struct pipe_fence_handle
**pfence
);
184 * Context ID used to fill in the commands
186 * Context IDs are arbitrary small non-negative integers,
187 * global to the entire SVGA device.
192 ** BEGIN new functions for guest-backed surfaces.
195 boolean have_gb_objects
;
198 * Map a guest-backed surface.
199 * \param flags bitmaks of PIPE_TRANSFER_x flags
201 * The surface_map() member is allowed to fail due to a
202 * shortage of command buffer space, if the
203 * PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE bit is set in flags.
204 * In that case, the caller must flush the current command
205 * buffer and reissue the map.
208 (*surface_map
)(struct svga_winsys_context
*swc
,
209 struct svga_winsys_surface
*surface
,
210 unsigned flags
, boolean
*retry
);
213 * Unmap a guest-backed surface.
214 * \param rebind returns a flag indicating whether the caller should
215 * issue a SVGA3D_BindGBSurface() call.
218 (*surface_unmap
)(struct svga_winsys_context
*swc
,
219 struct svga_winsys_surface
*surface
,
226 * SVGA per-screen winsys interface.
228 struct svga_winsys_screen
231 (*destroy
)(struct svga_winsys_screen
*sws
);
233 SVGA3dHardwareVersion
234 (*get_hw_version
)(struct svga_winsys_screen
*sws
);
237 (*get_cap
)(struct svga_winsys_screen
*sws
,
238 SVGA3dDevCapIndex index
,
239 SVGA3dDevCapResult
*result
);
242 * Create a new context.
244 * Context objects encapsulate all render state, and shader
245 * objects are per-context.
247 * Surfaces are not per-context. The same surface can be shared
248 * between multiple contexts, and surface operations can occur
251 struct svga_winsys_context
*
252 (*context_create
)(struct svga_winsys_screen
*sws
);
256 * This creates a "surface" object in the SVGA3D device.
258 * \param sws Pointer to an svga_winsys_context
259 * \param flags Device surface create flags
260 * \param format Format Device surface format
261 * \param usage Winsys usage: bitmask of SVGA_SURFACE_USAGE_x flags
262 * \param size Surface size given in device format
263 * \param numFaces Number of faces of the surface (1 or 6)
264 * \param numMipLevels Number of mipmap levels for each face
266 * Returns the surface ID (sid). Surfaces are generic
267 * containers for host VRAM objects like textures, vertex
268 * buffers, and depth/stencil buffers.
270 * Surfaces are hierarchial:
272 * - Surface may have multiple faces (for cube maps)
274 * - Each face has a list of mipmap levels
276 * - Each mipmap image may have multiple volume
277 * slices, if the image is three dimensional.
279 * - Each slice is a 2D array of 'blocks'
281 * - Each block may be one or more pixels.
282 * (Usually 1, more for DXT or YUV formats.)
284 * Surfaces are generic host VRAM objects. The SVGA3D device
285 * may optimize surfaces according to the format they were
286 * created with, but this format does not limit the ways in
287 * which the surface may be used. For example, a depth surface
288 * can be used as a texture, or a floating point image may
289 * be used as a vertex buffer. Some surface usages may be
290 * lower performance, due to software emulation, but any
291 * usage should work with any surface.
293 struct svga_winsys_surface
*
294 (*surface_create
)(struct svga_winsys_screen
*sws
,
295 SVGA3dSurfaceFlags flags
,
296 SVGA3dSurfaceFormat format
,
300 uint32 numMipLevels
);
303 * Creates a surface from a winsys handle.
304 * Used to implement pipe_screen::resource_from_handle.
306 struct svga_winsys_surface
*
307 (*surface_from_handle
)(struct svga_winsys_screen
*sws
,
308 struct winsys_handle
*whandle
,
309 SVGA3dSurfaceFormat
*format
);
312 * Get a winsys_handle from a surface.
313 * Used to implement pipe_screen::resource_get_handle.
316 (*surface_get_handle
)(struct svga_winsys_screen
*sws
,
317 struct svga_winsys_surface
*surface
,
319 struct winsys_handle
*whandle
);
322 * Whether this surface is sitting in a validate list
325 (*surface_is_flushed
)(struct svga_winsys_screen
*sws
,
326 struct svga_winsys_surface
*surface
);
329 * Reference a SVGA3D surface object. This allows sharing of a
330 * surface between different objects.
333 (*surface_reference
)(struct svga_winsys_screen
*sws
,
334 struct svga_winsys_surface
**pdst
,
335 struct svga_winsys_surface
*src
);
338 * Check if a resource (texture, buffer) of the given size
339 * and format can be created.
340 * \Return TRUE if OK, FALSE if too large.
343 (*surface_can_create
)(struct svga_winsys_screen
*sws
,
344 SVGA3dSurfaceFormat format
,
347 uint32 numMipLevels
);
350 * Buffer management. Buffer attributes are mostly fixed over its lifetime.
352 * @param usage bitmask of SVGA_BUFFER_USAGE_* flags.
354 * alignment indicates the client's alignment requirements, eg for
357 struct svga_winsys_buffer
*
358 (*buffer_create
)( struct svga_winsys_screen
*sws
,
364 * Map the entire data store of a buffer object into the client's address.
365 * usage is a bitmask of PIPE_TRANSFER_*
368 (*buffer_map
)( struct svga_winsys_screen
*sws
,
369 struct svga_winsys_buffer
*buf
,
373 (*buffer_unmap
)( struct svga_winsys_screen
*sws
,
374 struct svga_winsys_buffer
*buf
);
377 (*buffer_destroy
)( struct svga_winsys_screen
*sws
,
378 struct svga_winsys_buffer
*buf
);
382 * Reference a fence object.
385 (*fence_reference
)( struct svga_winsys_screen
*sws
,
386 struct pipe_fence_handle
**pdst
,
387 struct pipe_fence_handle
*src
);
390 * Checks whether the fence has been signalled.
391 * \param flags driver-specific meaning
392 * \return zero on success.
394 int (*fence_signalled
)( struct svga_winsys_screen
*sws
,
395 struct pipe_fence_handle
*fence
,
399 * Wait for the fence to finish.
400 * \param flags driver-specific meaning
401 * \return zero on success.
403 int (*fence_finish
)( struct svga_winsys_screen
*sws
,
404 struct pipe_fence_handle
*fence
,
409 ** BEGIN new functions for guest-backed surfaces.
412 /** Are guest-backed objects enabled? */
413 bool have_gb_objects
;
415 /** Can we do DMA with guest-backed objects enabled? */
419 * Create and define a GB shader.
421 struct svga_winsys_gb_shader
*
422 (*shader_create
)(struct svga_winsys_screen
*sws
,
423 SVGA3dShaderType type
,
424 const uint32
*bytecode
,
428 * Destroy a GB shader. It's safe to call this function even
429 * if the shader is referenced in a context's command stream.
432 (*shader_destroy
)(struct svga_winsys_screen
*sws
,
433 struct svga_winsys_gb_shader
*shader
);
438 struct svga_winsys_screen
*
439 svga_winsys_screen(struct pipe_screen
*screen
);
441 struct svga_winsys_context
*
442 svga_winsys_context(struct pipe_context
*context
);
444 struct pipe_resource
*
445 svga_screen_buffer_wrap_surface(struct pipe_screen
*screen
,
446 enum SVGA3dSurfaceFormat format
,
447 struct svga_winsys_surface
*srf
);
449 struct svga_winsys_surface
*
450 svga_screen_buffer_get_winsys_surface(struct pipe_resource
*buffer
);
452 #endif /* SVGA_WINSYS_H_ */