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_debug_callback
;
52 struct pipe_fence_handle
;
58 #define SVGA_BUFFER_USAGE_PINNED (1 << 0)
59 #define SVGA_BUFFER_USAGE_WRAPPED (1 << 1)
60 #define SVGA_BUFFER_USAGE_SHADER (1 << 2)
63 * Relocation flags to help with dirty tracking
64 * SVGA_RELOC_WRITE - The command will cause a GPU write to this
66 * SVGA_RELOC_READ - The command will cause a GPU read from this
68 * SVGA_RELOC_INTERNAL The command will only transfer data internally
69 * within the resource, and optionally clear
71 * SVGA_RELOC_DMA - Only set for resource buffer DMA uploads for winsys
72 * implementations that want to track the amount
73 * of such data referenced in the command stream.
75 #define SVGA_RELOC_WRITE (1 << 0)
76 #define SVGA_RELOC_READ (1 << 1)
77 #define SVGA_RELOC_INTERNAL (1 << 2)
78 #define SVGA_RELOC_DMA (1 << 3)
80 #define SVGA_FENCE_FLAG_EXEC (1 << 0)
81 #define SVGA_FENCE_FLAG_QUERY (1 << 1)
83 #define SVGA_SURFACE_USAGE_SHARED (1 << 0)
84 #define SVGA_SURFACE_USAGE_SCANOUT (1 << 1)
86 #define SVGA_QUERY_FLAG_SET (1 << 0)
87 #define SVGA_QUERY_FLAG_REF (1 << 1)
89 #define SVGA_HINT_FLAG_CAN_PRE_FLUSH (1 << 0) /* Can preemptively flush */
91 /** Opaque surface handle */
92 struct svga_winsys_surface
;
94 /** Opaque guest-backed objects */
95 struct svga_winsys_gb_shader
;
96 struct svga_winsys_gb_query
;
100 * SVGA per-context winsys interface.
102 struct svga_winsys_context
105 (*destroy
)(struct svga_winsys_context
*swc
);
108 (*reserve
)(struct svga_winsys_context
*swc
,
109 uint32_t nr_bytes
, uint32_t nr_relocs
);
112 * Returns current size of command buffer, in bytes.
115 (*get_command_buffer_size
)(struct svga_winsys_context
*swc
);
118 * Emit a relocation for a host surface.
120 * @param flags bitmask of SVGA_RELOC_* flags
122 * NOTE: Order of this call does matter. It should be the same order
123 * as relocations appear in the command buffer.
126 (*surface_relocation
)(struct svga_winsys_context
*swc
,
129 struct svga_winsys_surface
*surface
,
133 * Emit a relocation for a guest memory region.
135 * @param flags bitmask of SVGA_RELOC_* flags
137 * NOTE: Order of this call does matter. It should be the same order
138 * as relocations appear in the command buffer.
141 (*region_relocation
)(struct svga_winsys_context
*swc
,
142 struct SVGAGuestPtr
*ptr
,
143 struct svga_winsys_buffer
*buffer
,
148 * Emit a relocation for a guest-backed shader object.
150 * NOTE: Order of this call does matter. It should be the same order
151 * as relocations appear in the command buffer.
154 (*shader_relocation
)(struct svga_winsys_context
*swc
,
158 struct svga_winsys_gb_shader
*shader
,
162 * Emit a relocation for a guest-backed context.
164 * NOTE: Order of this call does matter. It should be the same order
165 * as relocations appear in the command buffer.
168 (*context_relocation
)(struct svga_winsys_context
*swc
, uint32
*cid
);
171 * Emit a relocation for a guest Memory OBject.
173 * @param flags bitmask of SVGA_RELOC_* flags
174 * @param offset_into_mob Buffer starts at this offset into the MOB.
176 * Note that not all commands accept an offset into the MOB and
177 * those commands can't use suballocated buffer pools. To trap
178 * errors from improper buffer pool usage, set the offset_into_mob
182 (*mob_relocation
)(struct svga_winsys_context
*swc
,
184 uint32
*offset_into_mob
,
185 struct svga_winsys_buffer
*buffer
,
190 * Emit a relocation for a guest-backed query object.
192 * NOTE: Order of this call does matter. It should be the same order
193 * as relocations appear in the command buffer.
196 (*query_relocation
)(struct svga_winsys_context
*swc
,
198 struct svga_winsys_gb_query
*query
);
201 * Bind queries to context.
202 * \param flags exactly one of SVGA_QUERY_FLAG_SET/REF
205 (*query_bind
)(struct svga_winsys_context
*sws
,
206 struct svga_winsys_gb_query
*query
,
210 (*commit
)(struct svga_winsys_context
*swc
);
213 (*flush
)(struct svga_winsys_context
*swc
,
214 struct pipe_fence_handle
**pfence
);
217 * Context ID used to fill in the commands
219 * Context IDs are arbitrary small non-negative integers,
220 * global to the entire SVGA device.
225 * Flags to hint the current context state
230 ** BEGIN new functions for guest-backed surfaces.
233 boolean have_gb_objects
;
236 * Map a guest-backed surface.
237 * \param flags bitmaks of PIPE_TRANSFER_x flags
239 * The surface_map() member is allowed to fail due to a
240 * shortage of command buffer space, if the
241 * PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE bit is set in flags.
242 * In that case, the caller must flush the current command
243 * buffer and reissue the map.
246 (*surface_map
)(struct svga_winsys_context
*swc
,
247 struct svga_winsys_surface
*surface
,
248 unsigned flags
, boolean
*retry
);
251 * Unmap a guest-backed surface.
252 * \param rebind returns a flag indicating whether the caller should
253 * issue a SVGA3D_BindGBSurface() call.
256 (*surface_unmap
)(struct svga_winsys_context
*swc
,
257 struct svga_winsys_surface
*surface
,
261 * Create and define a DX GB shader that resides in the device COTable.
262 * Caller of this function will issue the DXDefineShader command.
264 struct svga_winsys_gb_shader
*
265 (*shader_create
)(struct svga_winsys_context
*swc
,
267 SVGA3dShaderType shaderType
,
268 const uint32
*bytecode
,
272 * Destroy a DX GB shader.
273 * This function will issue the DXDestroyShader command.
276 (*shader_destroy
)(struct svga_winsys_context
*swc
,
277 struct svga_winsys_gb_shader
*shader
);
280 * Rebind a DX GB resource to a context.
281 * This is called to reference a DX GB resource in the command stream in
282 * order to page in the associated resource in case the memory has been
283 * paged out, and to fence it if necessary after command submission.
286 (*resource_rebind
)(struct svga_winsys_context
*swc
,
287 struct svga_winsys_surface
*surface
,
288 struct svga_winsys_gb_shader
*shader
,
291 /** To report perf/conformance/etc issues to the state tracker */
292 struct pipe_debug_callback
*debug_callback
;
297 * SVGA per-screen winsys interface.
299 struct svga_winsys_screen
302 (*destroy
)(struct svga_winsys_screen
*sws
);
304 SVGA3dHardwareVersion
305 (*get_hw_version
)(struct svga_winsys_screen
*sws
);
308 (*get_cap
)(struct svga_winsys_screen
*sws
,
309 SVGA3dDevCapIndex index
,
310 SVGA3dDevCapResult
*result
);
313 * Create a new context.
315 * Context objects encapsulate all render state, and shader
316 * objects are per-context.
318 * Surfaces are not per-context. The same surface can be shared
319 * between multiple contexts, and surface operations can occur
322 struct svga_winsys_context
*
323 (*context_create
)(struct svga_winsys_screen
*sws
);
327 * This creates a "surface" object in the SVGA3D device.
329 * \param sws Pointer to an svga_winsys_context
330 * \param flags Device surface create flags
331 * \param format Format Device surface format
332 * \param usage Winsys usage: bitmask of SVGA_SURFACE_USAGE_x flags
333 * \param size Surface size given in device format
334 * \param numLayers Number of layers of the surface (or cube faces)
335 * \param numMipLevels Number of mipmap levels for each face
337 * Returns the surface ID (sid). Surfaces are generic
338 * containers for host VRAM objects like textures, vertex
339 * buffers, and depth/stencil buffers.
341 * Surfaces are hierarchial:
343 * - Surface may have multiple faces (for cube maps)
345 * - Each face has a list of mipmap levels
347 * - Each mipmap image may have multiple volume
348 * slices for 3D image, or multiple 2D slices for texture array.
350 * - Each slice is a 2D array of 'blocks'
352 * - Each block may be one or more pixels.
353 * (Usually 1, more for DXT or YUV formats.)
355 * Surfaces are generic host VRAM objects. The SVGA3D device
356 * may optimize surfaces according to the format they were
357 * created with, but this format does not limit the ways in
358 * which the surface may be used. For example, a depth surface
359 * can be used as a texture, or a floating point image may
360 * be used as a vertex buffer. Some surface usages may be
361 * lower performance, due to software emulation, but any
362 * usage should work with any surface.
364 struct svga_winsys_surface
*
365 (*surface_create
)(struct svga_winsys_screen
*sws
,
366 SVGA3dSurfaceFlags flags
,
367 SVGA3dSurfaceFormat format
,
372 unsigned sampleCount
);
375 * Creates a surface from a winsys handle.
376 * Used to implement pipe_screen::resource_from_handle.
378 struct svga_winsys_surface
*
379 (*surface_from_handle
)(struct svga_winsys_screen
*sws
,
380 struct winsys_handle
*whandle
,
381 SVGA3dSurfaceFormat
*format
);
384 * Get a winsys_handle from a surface.
385 * Used to implement pipe_screen::resource_get_handle.
388 (*surface_get_handle
)(struct svga_winsys_screen
*sws
,
389 struct svga_winsys_surface
*surface
,
391 struct winsys_handle
*whandle
);
394 * Whether this surface is sitting in a validate list
397 (*surface_is_flushed
)(struct svga_winsys_screen
*sws
,
398 struct svga_winsys_surface
*surface
);
401 * Reference a SVGA3D surface object. This allows sharing of a
402 * surface between different objects.
405 (*surface_reference
)(struct svga_winsys_screen
*sws
,
406 struct svga_winsys_surface
**pdst
,
407 struct svga_winsys_surface
*src
);
410 * Check if a resource (texture, buffer) of the given size
411 * and format can be created.
412 * \Return TRUE if OK, FALSE if too large.
415 (*surface_can_create
)(struct svga_winsys_screen
*sws
,
416 SVGA3dSurfaceFormat format
,
419 uint32 numMipLevels
);
422 * Buffer management. Buffer attributes are mostly fixed over its lifetime.
424 * @param usage bitmask of SVGA_BUFFER_USAGE_* flags.
426 * alignment indicates the client's alignment requirements, eg for
429 struct svga_winsys_buffer
*
430 (*buffer_create
)( struct svga_winsys_screen
*sws
,
436 * Map the entire data store of a buffer object into the client's address.
437 * usage is a bitmask of PIPE_TRANSFER_*
440 (*buffer_map
)( struct svga_winsys_screen
*sws
,
441 struct svga_winsys_buffer
*buf
,
445 (*buffer_unmap
)( struct svga_winsys_screen
*sws
,
446 struct svga_winsys_buffer
*buf
);
449 (*buffer_destroy
)( struct svga_winsys_screen
*sws
,
450 struct svga_winsys_buffer
*buf
);
454 * Reference a fence object.
457 (*fence_reference
)( struct svga_winsys_screen
*sws
,
458 struct pipe_fence_handle
**pdst
,
459 struct pipe_fence_handle
*src
);
462 * Checks whether the fence has been signalled.
463 * \param flags driver-specific meaning
464 * \return zero on success.
466 int (*fence_signalled
)( struct svga_winsys_screen
*sws
,
467 struct pipe_fence_handle
*fence
,
471 * Wait for the fence to finish.
472 * \param flags driver-specific meaning
473 * \return zero on success.
475 int (*fence_finish
)( struct svga_winsys_screen
*sws
,
476 struct pipe_fence_handle
*fence
,
481 ** BEGIN new functions for guest-backed surfaces.
484 /** Are guest-backed objects enabled? */
485 bool have_gb_objects
;
487 /** Can we do DMA with guest-backed objects enabled? */
491 * Create and define a GB shader.
493 struct svga_winsys_gb_shader
*
494 (*shader_create
)(struct svga_winsys_screen
*sws
,
495 SVGA3dShaderType shaderType
,
496 const uint32
*bytecode
,
500 * Destroy a GB shader. It's safe to call this function even
501 * if the shader is referenced in a context's command stream.
504 (*shader_destroy
)(struct svga_winsys_screen
*sws
,
505 struct svga_winsys_gb_shader
*shader
);
508 * Create and define a GB query.
510 struct svga_winsys_gb_query
*
511 (*query_create
)(struct svga_winsys_screen
*sws
, uint32 len
);
514 * Destroy a GB query.
517 (*query_destroy
)(struct svga_winsys_screen
*sws
,
518 struct svga_winsys_gb_query
*query
);
521 * Initialize the query state of the query that resides in the slot
522 * specified in offset
523 * \return zero on success.
526 (*query_init
)(struct svga_winsys_screen
*sws
,
527 struct svga_winsys_gb_query
*query
,
529 SVGA3dQueryState queryState
);
532 * Inquire for the query state and result of the query that resides
533 * in the slot specified in offset
536 (*query_get_result
)(struct svga_winsys_screen
*sws
,
537 struct svga_winsys_gb_query
*query
,
539 SVGA3dQueryState
*queryState
,
540 void *result
, uint32 resultLen
);
542 /** Have VGPU v10 hardware? */
545 /** To rebind resources at the beginnning of a new command buffer */
546 boolean need_to_rebind_resources
;
550 struct svga_winsys_screen
*
551 svga_winsys_screen(struct pipe_screen
*screen
);
553 struct svga_winsys_context
*
554 svga_winsys_context(struct pipe_context
*context
);
556 struct pipe_resource
*
557 svga_screen_buffer_wrap_surface(struct pipe_screen
*screen
,
558 enum SVGA3dSurfaceFormat format
,
559 struct svga_winsys_surface
*srf
);
561 struct svga_winsys_surface
*
562 svga_screen_buffer_get_winsys_surface(struct pipe_resource
*buffer
);
564 #endif /* SVGA_WINSYS_H_ */