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)
83 #define SVGA_SURFACE_USAGE_SCANOUT (1 << 1)
85 #define SVGA_QUERY_FLAG_SET (1 << 0)
86 #define SVGA_QUERY_FLAG_REF (1 << 1)
88 #define SVGA_HINT_FLAG_CAN_PRE_FLUSH (1 << 0) /* Can preemptively flush */
90 /** Opaque surface handle */
91 struct svga_winsys_surface
;
93 /** Opaque guest-backed objects */
94 struct svga_winsys_gb_shader
;
95 struct svga_winsys_gb_query
;
99 * SVGA per-context winsys interface.
101 struct svga_winsys_context
104 (*destroy
)(struct svga_winsys_context
*swc
);
107 (*reserve
)(struct svga_winsys_context
*swc
,
108 uint32_t nr_bytes
, uint32_t nr_relocs
);
111 * Returns current size of command buffer, in bytes.
114 (*get_command_buffer_size
)(struct svga_winsys_context
*swc
);
117 * Emit a relocation for a host surface.
119 * @param flags bitmask of SVGA_RELOC_* flags
121 * NOTE: Order of this call does matter. It should be the same order
122 * as relocations appear in the command buffer.
125 (*surface_relocation
)(struct svga_winsys_context
*swc
,
128 struct svga_winsys_surface
*surface
,
132 * Emit a relocation for a guest memory region.
134 * @param flags bitmask of SVGA_RELOC_* flags
136 * NOTE: Order of this call does matter. It should be the same order
137 * as relocations appear in the command buffer.
140 (*region_relocation
)(struct svga_winsys_context
*swc
,
141 struct SVGAGuestPtr
*ptr
,
142 struct svga_winsys_buffer
*buffer
,
147 * Emit a relocation for a guest-backed shader object.
149 * NOTE: Order of this call does matter. It should be the same order
150 * as relocations appear in the command buffer.
153 (*shader_relocation
)(struct svga_winsys_context
*swc
,
157 struct svga_winsys_gb_shader
*shader
,
161 * Emit a relocation for a guest-backed context.
163 * NOTE: Order of this call does matter. It should be the same order
164 * as relocations appear in the command buffer.
167 (*context_relocation
)(struct svga_winsys_context
*swc
, uint32
*cid
);
170 * Emit a relocation for a guest Memory OBject.
172 * @param flags bitmask of SVGA_RELOC_* flags
173 * @param offset_into_mob Buffer starts at this offset into the MOB.
175 * Note that not all commands accept an offset into the MOB and
176 * those commands can't use suballocated buffer pools. To trap
177 * errors from improper buffer pool usage, set the offset_into_mob
181 (*mob_relocation
)(struct svga_winsys_context
*swc
,
183 uint32
*offset_into_mob
,
184 struct svga_winsys_buffer
*buffer
,
189 * Emit a relocation for a guest-backed query object.
191 * NOTE: Order of this call does matter. It should be the same order
192 * as relocations appear in the command buffer.
195 (*query_relocation
)(struct svga_winsys_context
*swc
,
197 struct svga_winsys_gb_query
*query
);
200 * Bind queries to context.
201 * \param flags exactly one of SVGA_QUERY_FLAG_SET/REF
204 (*query_bind
)(struct svga_winsys_context
*sws
,
205 struct svga_winsys_gb_query
*query
,
209 (*commit
)(struct svga_winsys_context
*swc
);
212 (*flush
)(struct svga_winsys_context
*swc
,
213 struct pipe_fence_handle
**pfence
);
216 * Context ID used to fill in the commands
218 * Context IDs are arbitrary small non-negative integers,
219 * global to the entire SVGA device.
224 * Flags to hint the current context state
229 ** BEGIN new functions for guest-backed surfaces.
232 boolean have_gb_objects
;
235 * Map a guest-backed surface.
236 * \param flags bitmaks of PIPE_TRANSFER_x flags
238 * The surface_map() member is allowed to fail due to a
239 * shortage of command buffer space, if the
240 * PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE bit is set in flags.
241 * In that case, the caller must flush the current command
242 * buffer and reissue the map.
245 (*surface_map
)(struct svga_winsys_context
*swc
,
246 struct svga_winsys_surface
*surface
,
247 unsigned flags
, boolean
*retry
);
250 * Unmap a guest-backed surface.
251 * \param rebind returns a flag indicating whether the caller should
252 * issue a SVGA3D_BindGBSurface() call.
255 (*surface_unmap
)(struct svga_winsys_context
*swc
,
256 struct svga_winsys_surface
*surface
,
260 * Create and define a DX GB shader that resides in the device COTable.
261 * Caller of this function will issue the DXDefineShader command.
263 struct svga_winsys_gb_shader
*
264 (*shader_create
)(struct svga_winsys_context
*swc
,
266 SVGA3dShaderType shaderType
,
267 const uint32
*bytecode
,
271 * Destroy a DX GB shader.
272 * This function will issue the DXDestroyShader command.
275 (*shader_destroy
)(struct svga_winsys_context
*swc
,
276 struct svga_winsys_gb_shader
*shader
);
279 * Rebind a DX GB resource to a context.
280 * This is called to reference a DX GB resource in the command stream in
281 * order to page in the associated resource in case the memory has been
282 * paged out, and to fence it if necessary after command submission.
285 (*resource_rebind
)(struct svga_winsys_context
*swc
,
286 struct svga_winsys_surface
*surface
,
287 struct svga_winsys_gb_shader
*shader
,
293 * SVGA per-screen winsys interface.
295 struct svga_winsys_screen
298 (*destroy
)(struct svga_winsys_screen
*sws
);
300 SVGA3dHardwareVersion
301 (*get_hw_version
)(struct svga_winsys_screen
*sws
);
304 (*get_cap
)(struct svga_winsys_screen
*sws
,
305 SVGA3dDevCapIndex index
,
306 SVGA3dDevCapResult
*result
);
309 * Create a new context.
311 * Context objects encapsulate all render state, and shader
312 * objects are per-context.
314 * Surfaces are not per-context. The same surface can be shared
315 * between multiple contexts, and surface operations can occur
318 struct svga_winsys_context
*
319 (*context_create
)(struct svga_winsys_screen
*sws
);
323 * This creates a "surface" object in the SVGA3D device.
325 * \param sws Pointer to an svga_winsys_context
326 * \param flags Device surface create flags
327 * \param format Format Device surface format
328 * \param usage Winsys usage: bitmask of SVGA_SURFACE_USAGE_x flags
329 * \param size Surface size given in device format
330 * \param numLayers Number of layers of the surface (or cube faces)
331 * \param numMipLevels Number of mipmap levels for each face
333 * Returns the surface ID (sid). Surfaces are generic
334 * containers for host VRAM objects like textures, vertex
335 * buffers, and depth/stencil buffers.
337 * Surfaces are hierarchial:
339 * - Surface may have multiple faces (for cube maps)
341 * - Each face has a list of mipmap levels
343 * - Each mipmap image may have multiple volume
344 * slices for 3D image, or multiple 2D slices for texture array.
346 * - Each slice is a 2D array of 'blocks'
348 * - Each block may be one or more pixels.
349 * (Usually 1, more for DXT or YUV formats.)
351 * Surfaces are generic host VRAM objects. The SVGA3D device
352 * may optimize surfaces according to the format they were
353 * created with, but this format does not limit the ways in
354 * which the surface may be used. For example, a depth surface
355 * can be used as a texture, or a floating point image may
356 * be used as a vertex buffer. Some surface usages may be
357 * lower performance, due to software emulation, but any
358 * usage should work with any surface.
360 struct svga_winsys_surface
*
361 (*surface_create
)(struct svga_winsys_screen
*sws
,
362 SVGA3dSurfaceFlags flags
,
363 SVGA3dSurfaceFormat format
,
368 unsigned sampleCount
);
371 * Creates a surface from a winsys handle.
372 * Used to implement pipe_screen::resource_from_handle.
374 struct svga_winsys_surface
*
375 (*surface_from_handle
)(struct svga_winsys_screen
*sws
,
376 struct winsys_handle
*whandle
,
377 SVGA3dSurfaceFormat
*format
);
380 * Get a winsys_handle from a surface.
381 * Used to implement pipe_screen::resource_get_handle.
384 (*surface_get_handle
)(struct svga_winsys_screen
*sws
,
385 struct svga_winsys_surface
*surface
,
387 struct winsys_handle
*whandle
);
390 * Whether this surface is sitting in a validate list
393 (*surface_is_flushed
)(struct svga_winsys_screen
*sws
,
394 struct svga_winsys_surface
*surface
);
397 * Reference a SVGA3D surface object. This allows sharing of a
398 * surface between different objects.
401 (*surface_reference
)(struct svga_winsys_screen
*sws
,
402 struct svga_winsys_surface
**pdst
,
403 struct svga_winsys_surface
*src
);
406 * Check if a resource (texture, buffer) of the given size
407 * and format can be created.
408 * \Return TRUE if OK, FALSE if too large.
411 (*surface_can_create
)(struct svga_winsys_screen
*sws
,
412 SVGA3dSurfaceFormat format
,
415 uint32 numMipLevels
);
418 * Buffer management. Buffer attributes are mostly fixed over its lifetime.
420 * @param usage bitmask of SVGA_BUFFER_USAGE_* flags.
422 * alignment indicates the client's alignment requirements, eg for
425 struct svga_winsys_buffer
*
426 (*buffer_create
)( struct svga_winsys_screen
*sws
,
432 * Map the entire data store of a buffer object into the client's address.
433 * usage is a bitmask of PIPE_TRANSFER_*
436 (*buffer_map
)( struct svga_winsys_screen
*sws
,
437 struct svga_winsys_buffer
*buf
,
441 (*buffer_unmap
)( struct svga_winsys_screen
*sws
,
442 struct svga_winsys_buffer
*buf
);
445 (*buffer_destroy
)( struct svga_winsys_screen
*sws
,
446 struct svga_winsys_buffer
*buf
);
450 * Reference a fence object.
453 (*fence_reference
)( struct svga_winsys_screen
*sws
,
454 struct pipe_fence_handle
**pdst
,
455 struct pipe_fence_handle
*src
);
458 * Checks whether the fence has been signalled.
459 * \param flags driver-specific meaning
460 * \return zero on success.
462 int (*fence_signalled
)( struct svga_winsys_screen
*sws
,
463 struct pipe_fence_handle
*fence
,
467 * Wait for the fence to finish.
468 * \param flags driver-specific meaning
469 * \return zero on success.
471 int (*fence_finish
)( struct svga_winsys_screen
*sws
,
472 struct pipe_fence_handle
*fence
,
477 ** BEGIN new functions for guest-backed surfaces.
480 /** Are guest-backed objects enabled? */
481 bool have_gb_objects
;
483 /** Can we do DMA with guest-backed objects enabled? */
487 * Create and define a GB shader.
489 struct svga_winsys_gb_shader
*
490 (*shader_create
)(struct svga_winsys_screen
*sws
,
491 SVGA3dShaderType shaderType
,
492 const uint32
*bytecode
,
496 * Destroy a GB shader. It's safe to call this function even
497 * if the shader is referenced in a context's command stream.
500 (*shader_destroy
)(struct svga_winsys_screen
*sws
,
501 struct svga_winsys_gb_shader
*shader
);
504 * Create and define a GB query.
506 struct svga_winsys_gb_query
*
507 (*query_create
)(struct svga_winsys_screen
*sws
, uint32 len
);
510 * Destroy a GB query.
513 (*query_destroy
)(struct svga_winsys_screen
*sws
,
514 struct svga_winsys_gb_query
*query
);
517 * Initialize the query state of the query that resides in the slot
518 * specified in offset
519 * \return zero on success.
522 (*query_init
)(struct svga_winsys_screen
*sws
,
523 struct svga_winsys_gb_query
*query
,
525 SVGA3dQueryState queryState
);
528 * Inquire for the query state and result of the query that resides
529 * in the slot specified in offset
532 (*query_get_result
)(struct svga_winsys_screen
*sws
,
533 struct svga_winsys_gb_query
*query
,
535 SVGA3dQueryState
*queryState
,
536 void *result
, uint32 resultLen
);
538 /** Have VGPU v10 hardware? */
541 /** To rebind resources at the beginnning of a new command buffer */
542 boolean need_to_rebind_resources
;
546 struct svga_winsys_screen
*
547 svga_winsys_screen(struct pipe_screen
*screen
);
549 struct svga_winsys_context
*
550 svga_winsys_context(struct pipe_context
*context
);
552 struct pipe_resource
*
553 svga_screen_buffer_wrap_surface(struct pipe_screen
*screen
,
554 enum SVGA3dSurfaceFormat format
,
555 struct svga_winsys_surface
*srf
);
557 struct svga_winsys_surface
*
558 svga_screen_buffer_get_winsys_surface(struct pipe_resource
*buffer
);
560 #endif /* SVGA_WINSYS_H_ */