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 * Emit a relocation for a host surface.
113 * @param flags bitmask of SVGA_RELOC_* flags
115 * NOTE: Order of this call does matter. It should be the same order
116 * as relocations appear in the command buffer.
119 (*surface_relocation
)(struct svga_winsys_context
*swc
,
122 struct svga_winsys_surface
*surface
,
126 * Emit a relocation for a guest memory region.
128 * @param flags bitmask of SVGA_RELOC_* flags
130 * NOTE: Order of this call does matter. It should be the same order
131 * as relocations appear in the command buffer.
134 (*region_relocation
)(struct svga_winsys_context
*swc
,
135 struct SVGAGuestPtr
*ptr
,
136 struct svga_winsys_buffer
*buffer
,
141 * Emit a relocation for a guest-backed shader object.
143 * NOTE: Order of this call does matter. It should be the same order
144 * as relocations appear in the command buffer.
147 (*shader_relocation
)(struct svga_winsys_context
*swc
,
151 struct svga_winsys_gb_shader
*shader
,
155 * Emit a relocation for a guest-backed context.
157 * NOTE: Order of this call does matter. It should be the same order
158 * as relocations appear in the command buffer.
161 (*context_relocation
)(struct svga_winsys_context
*swc
, uint32
*cid
);
164 * Emit a relocation for a guest Memory OBject.
166 * @param flags bitmask of SVGA_RELOC_* flags
167 * @param offset_into_mob Buffer starts at this offset into the MOB.
169 * Note that not all commands accept an offset into the MOB and
170 * those commands can't use suballocated buffer pools. To trap
171 * errors from improper buffer pool usage, set the offset_into_mob
175 (*mob_relocation
)(struct svga_winsys_context
*swc
,
177 uint32
*offset_into_mob
,
178 struct svga_winsys_buffer
*buffer
,
183 * Emit a relocation for a guest-backed query object.
185 * NOTE: Order of this call does matter. It should be the same order
186 * as relocations appear in the command buffer.
189 (*query_relocation
)(struct svga_winsys_context
*swc
,
191 struct svga_winsys_gb_query
*query
);
194 * Bind queries to context.
195 * \param flags exactly one of SVGA_QUERY_FLAG_SET/REF
198 (*query_bind
)(struct svga_winsys_context
*sws
,
199 struct svga_winsys_gb_query
*query
,
203 (*commit
)(struct svga_winsys_context
*swc
);
206 (*flush
)(struct svga_winsys_context
*swc
,
207 struct pipe_fence_handle
**pfence
);
210 * Context ID used to fill in the commands
212 * Context IDs are arbitrary small non-negative integers,
213 * global to the entire SVGA device.
218 * Flags to hint the current context state
223 ** BEGIN new functions for guest-backed surfaces.
226 boolean have_gb_objects
;
229 * Map a guest-backed surface.
230 * \param flags bitmaks of PIPE_TRANSFER_x flags
232 * The surface_map() member is allowed to fail due to a
233 * shortage of command buffer space, if the
234 * PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE bit is set in flags.
235 * In that case, the caller must flush the current command
236 * buffer and reissue the map.
239 (*surface_map
)(struct svga_winsys_context
*swc
,
240 struct svga_winsys_surface
*surface
,
241 unsigned flags
, boolean
*retry
);
244 * Unmap a guest-backed surface.
245 * \param rebind returns a flag indicating whether the caller should
246 * issue a SVGA3D_BindGBSurface() call.
249 (*surface_unmap
)(struct svga_winsys_context
*swc
,
250 struct svga_winsys_surface
*surface
,
254 * Create and define a DX GB shader that resides in the device COTable.
255 * Caller of this function will issue the DXDefineShader command.
257 struct svga_winsys_gb_shader
*
258 (*shader_create
)(struct svga_winsys_context
*swc
,
260 SVGA3dShaderType shaderType
,
261 const uint32
*bytecode
,
265 * Destroy a DX GB shader.
266 * This function will issue the DXDestroyShader command.
269 (*shader_destroy
)(struct svga_winsys_context
*swc
,
270 struct svga_winsys_gb_shader
*shader
);
273 * Rebind a DX GB resource to a context.
274 * This is called to reference a DX GB resource in the command stream in
275 * order to page in the associated resource in case the memory has been
276 * paged out, and to fence it if necessary after command submission.
279 (*resource_rebind
)(struct svga_winsys_context
*swc
,
280 struct svga_winsys_surface
*surface
,
281 struct svga_winsys_gb_shader
*shader
,
287 * SVGA per-screen winsys interface.
289 struct svga_winsys_screen
292 (*destroy
)(struct svga_winsys_screen
*sws
);
294 SVGA3dHardwareVersion
295 (*get_hw_version
)(struct svga_winsys_screen
*sws
);
298 (*get_cap
)(struct svga_winsys_screen
*sws
,
299 SVGA3dDevCapIndex index
,
300 SVGA3dDevCapResult
*result
);
303 * Create a new context.
305 * Context objects encapsulate all render state, and shader
306 * objects are per-context.
308 * Surfaces are not per-context. The same surface can be shared
309 * between multiple contexts, and surface operations can occur
312 struct svga_winsys_context
*
313 (*context_create
)(struct svga_winsys_screen
*sws
);
317 * This creates a "surface" object in the SVGA3D device.
319 * \param sws Pointer to an svga_winsys_context
320 * \param flags Device surface create flags
321 * \param format Format Device surface format
322 * \param usage Winsys usage: bitmask of SVGA_SURFACE_USAGE_x flags
323 * \param size Surface size given in device format
324 * \param numLayers Number of layers of the surface (or cube faces)
325 * \param numMipLevels Number of mipmap levels for each face
327 * Returns the surface ID (sid). Surfaces are generic
328 * containers for host VRAM objects like textures, vertex
329 * buffers, and depth/stencil buffers.
331 * Surfaces are hierarchial:
333 * - Surface may have multiple faces (for cube maps)
335 * - Each face has a list of mipmap levels
337 * - Each mipmap image may have multiple volume
338 * slices for 3D image, or multiple 2D slices for texture array.
340 * - Each slice is a 2D array of 'blocks'
342 * - Each block may be one or more pixels.
343 * (Usually 1, more for DXT or YUV formats.)
345 * Surfaces are generic host VRAM objects. The SVGA3D device
346 * may optimize surfaces according to the format they were
347 * created with, but this format does not limit the ways in
348 * which the surface may be used. For example, a depth surface
349 * can be used as a texture, or a floating point image may
350 * be used as a vertex buffer. Some surface usages may be
351 * lower performance, due to software emulation, but any
352 * usage should work with any surface.
354 struct svga_winsys_surface
*
355 (*surface_create
)(struct svga_winsys_screen
*sws
,
356 SVGA3dSurfaceFlags flags
,
357 SVGA3dSurfaceFormat format
,
362 unsigned sampleCount
);
365 * Creates a surface from a winsys handle.
366 * Used to implement pipe_screen::resource_from_handle.
368 struct svga_winsys_surface
*
369 (*surface_from_handle
)(struct svga_winsys_screen
*sws
,
370 struct winsys_handle
*whandle
,
371 SVGA3dSurfaceFormat
*format
);
374 * Get a winsys_handle from a surface.
375 * Used to implement pipe_screen::resource_get_handle.
378 (*surface_get_handle
)(struct svga_winsys_screen
*sws
,
379 struct svga_winsys_surface
*surface
,
381 struct winsys_handle
*whandle
);
384 * Whether this surface is sitting in a validate list
387 (*surface_is_flushed
)(struct svga_winsys_screen
*sws
,
388 struct svga_winsys_surface
*surface
);
391 * Reference a SVGA3D surface object. This allows sharing of a
392 * surface between different objects.
395 (*surface_reference
)(struct svga_winsys_screen
*sws
,
396 struct svga_winsys_surface
**pdst
,
397 struct svga_winsys_surface
*src
);
400 * Check if a resource (texture, buffer) of the given size
401 * and format can be created.
402 * \Return TRUE if OK, FALSE if too large.
405 (*surface_can_create
)(struct svga_winsys_screen
*sws
,
406 SVGA3dSurfaceFormat format
,
409 uint32 numMipLevels
);
412 * Buffer management. Buffer attributes are mostly fixed over its lifetime.
414 * @param usage bitmask of SVGA_BUFFER_USAGE_* flags.
416 * alignment indicates the client's alignment requirements, eg for
419 struct svga_winsys_buffer
*
420 (*buffer_create
)( struct svga_winsys_screen
*sws
,
426 * Map the entire data store of a buffer object into the client's address.
427 * usage is a bitmask of PIPE_TRANSFER_*
430 (*buffer_map
)( struct svga_winsys_screen
*sws
,
431 struct svga_winsys_buffer
*buf
,
435 (*buffer_unmap
)( struct svga_winsys_screen
*sws
,
436 struct svga_winsys_buffer
*buf
);
439 (*buffer_destroy
)( struct svga_winsys_screen
*sws
,
440 struct svga_winsys_buffer
*buf
);
444 * Reference a fence object.
447 (*fence_reference
)( struct svga_winsys_screen
*sws
,
448 struct pipe_fence_handle
**pdst
,
449 struct pipe_fence_handle
*src
);
452 * Checks whether the fence has been signalled.
453 * \param flags driver-specific meaning
454 * \return zero on success.
456 int (*fence_signalled
)( struct svga_winsys_screen
*sws
,
457 struct pipe_fence_handle
*fence
,
461 * Wait for the fence to finish.
462 * \param flags driver-specific meaning
463 * \return zero on success.
465 int (*fence_finish
)( struct svga_winsys_screen
*sws
,
466 struct pipe_fence_handle
*fence
,
471 ** BEGIN new functions for guest-backed surfaces.
474 /** Are guest-backed objects enabled? */
475 bool have_gb_objects
;
477 /** Can we do DMA with guest-backed objects enabled? */
481 * Create and define a GB shader.
483 struct svga_winsys_gb_shader
*
484 (*shader_create
)(struct svga_winsys_screen
*sws
,
485 SVGA3dShaderType shaderType
,
486 const uint32
*bytecode
,
490 * Destroy a GB shader. It's safe to call this function even
491 * if the shader is referenced in a context's command stream.
494 (*shader_destroy
)(struct svga_winsys_screen
*sws
,
495 struct svga_winsys_gb_shader
*shader
);
498 * Create and define a GB query.
500 struct svga_winsys_gb_query
*
501 (*query_create
)(struct svga_winsys_screen
*sws
, uint32 len
);
504 * Destroy a GB query.
507 (*query_destroy
)(struct svga_winsys_screen
*sws
,
508 struct svga_winsys_gb_query
*query
);
511 * Initialize the query state of the query that resides in the slot
512 * specified in offset
513 * \return zero on success.
516 (*query_init
)(struct svga_winsys_screen
*sws
,
517 struct svga_winsys_gb_query
*query
,
519 SVGA3dQueryState queryState
);
522 * Inquire for the query state and result of the query that resides
523 * in the slot specified in offset
526 (*query_get_result
)(struct svga_winsys_screen
*sws
,
527 struct svga_winsys_gb_query
*query
,
529 SVGA3dQueryState
*queryState
,
530 void *result
, uint32 resultLen
);
532 /** Have VGPU v10 hardware? */
535 /** To rebind resources at the beginnning of a new command buffer */
536 boolean need_to_rebind_resources
;
540 struct svga_winsys_screen
*
541 svga_winsys_screen(struct pipe_screen
*screen
);
543 struct svga_winsys_context
*
544 svga_winsys_context(struct pipe_context
*context
);
546 struct pipe_resource
*
547 svga_screen_buffer_wrap_surface(struct pipe_screen
*screen
,
548 enum SVGA3dSurfaceFormat format
,
549 struct svga_winsys_surface
*srf
);
551 struct svga_winsys_surface
*
552 svga_screen_buffer_get_winsys_surface(struct pipe_resource
*buffer
);
554 #endif /* SVGA_WINSYS_H_ */