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"
46 #include "svga_mksstats.h"
48 struct svga_winsys_screen
;
49 struct svga_winsys_buffer
;
52 struct pipe_debug_callback
;
53 struct pipe_fence_handle
;
59 #define SVGA_BUFFER_USAGE_PINNED (1 << 0)
60 #define SVGA_BUFFER_USAGE_WRAPPED (1 << 1)
61 #define SVGA_BUFFER_USAGE_SHADER (1 << 2)
64 * Relocation flags to help with dirty tracking
65 * SVGA_RELOC_WRITE - The command will cause a GPU write to this
67 * SVGA_RELOC_READ - The command will cause a GPU read from this
69 * SVGA_RELOC_INTERNAL The command will only transfer data internally
70 * within the resource, and optionally clear
72 * SVGA_RELOC_DMA - Only set for resource buffer DMA uploads for winsys
73 * implementations that want to track the amount
74 * of such data referenced in the command stream.
76 #define SVGA_RELOC_WRITE (1 << 0)
77 #define SVGA_RELOC_READ (1 << 1)
78 #define SVGA_RELOC_INTERNAL (1 << 2)
79 #define SVGA_RELOC_DMA (1 << 3)
81 #define SVGA_FENCE_FLAG_EXEC (1 << 0)
82 #define SVGA_FENCE_FLAG_QUERY (1 << 1)
84 #define SVGA_SURFACE_USAGE_SHARED (1 << 0)
85 #define SVGA_SURFACE_USAGE_SCANOUT (1 << 1)
87 #define SVGA_QUERY_FLAG_SET (1 << 0)
88 #define SVGA_QUERY_FLAG_REF (1 << 1)
90 #define SVGA_HINT_FLAG_CAN_PRE_FLUSH (1 << 0) /* Can preemptively flush */
93 * SVGA mks statistics info
95 struct svga_winsys_stats_timeframe
{
98 uint64 adjustedStartTime
;
99 struct svga_winsys_stats_timeframe
*enclosing
;
102 enum svga_stats_count
{
103 SVGA_STATS_COUNT_BLENDSTATE
,
104 SVGA_STATS_COUNT_DEPTHSTENCILSTATE
,
105 SVGA_STATS_COUNT_RASTERIZERSTATE
,
106 SVGA_STATS_COUNT_SAMPLER
,
107 SVGA_STATS_COUNT_SAMPLERVIEW
,
108 SVGA_STATS_COUNT_SURFACEWRITEFLUSH
,
109 SVGA_STATS_COUNT_TEXREADBACK
,
110 SVGA_STATS_COUNT_VERTEXELEMENT
,
114 enum svga_stats_time
{
115 SVGA_STATS_TIME_BUFFERSFLUSH
,
116 SVGA_STATS_TIME_BUFFERTRANSFERMAP
,
117 SVGA_STATS_TIME_BUFFERTRANSFERUNMAP
,
118 SVGA_STATS_TIME_CONTEXTFINISH
,
119 SVGA_STATS_TIME_CONTEXTFLUSH
,
120 SVGA_STATS_TIME_CREATEBACKEDSURFACEVIEW
,
121 SVGA_STATS_TIME_CREATEBUFFER
,
122 SVGA_STATS_TIME_CREATECONTEXT
,
123 SVGA_STATS_TIME_CREATEFS
,
124 SVGA_STATS_TIME_CREATEGS
,
125 SVGA_STATS_TIME_CREATESURFACE
,
126 SVGA_STATS_TIME_CREATESURFACEVIEW
,
127 SVGA_STATS_TIME_CREATETEXTURE
,
128 SVGA_STATS_TIME_CREATEVS
,
129 SVGA_STATS_TIME_DEFINESHADER
,
130 SVGA_STATS_TIME_DESTROYSURFACE
,
131 SVGA_STATS_TIME_DRAWVBO
,
132 SVGA_STATS_TIME_DRAWARRAYS
,
133 SVGA_STATS_TIME_DRAWELEMENTS
,
134 SVGA_STATS_TIME_EMITFS
,
135 SVGA_STATS_TIME_EMITGS
,
136 SVGA_STATS_TIME_EMITVS
,
137 SVGA_STATS_TIME_FENCEFINISH
,
138 SVGA_STATS_TIME_GENERATEINDICES
,
139 SVGA_STATS_TIME_HWTNLDRAWARRAYS
,
140 SVGA_STATS_TIME_HWTNLDRAWELEMENTS
,
141 SVGA_STATS_TIME_HWTNLFLUSH
,
142 SVGA_STATS_TIME_HWTNLPRIM
,
143 SVGA_STATS_TIME_PROPAGATESURFACE
,
144 SVGA_STATS_TIME_SETSAMPLERVIEWS
,
145 SVGA_STATS_TIME_SURFACEFLUSH
,
146 SVGA_STATS_TIME_SWTNLDRAWVBO
,
147 SVGA_STATS_TIME_SWTNLUPDATEDRAW
,
148 SVGA_STATS_TIME_SWTNLUPDATEVDECL
,
149 SVGA_STATS_TIME_TEXTRANSFERMAP
,
150 SVGA_STATS_TIME_TEXTRANSFERUNMAP
,
151 SVGA_STATS_TIME_TGSIVGPU10TRANSLATE
,
152 SVGA_STATS_TIME_TGSIVGPU9TRANSLATE
,
153 SVGA_STATS_TIME_UPDATESTATE
,
154 SVGA_STATS_TIME_VALIDATESURFACEVIEW
,
155 SVGA_STATS_TIME_VBUFDRAWARRAYS
,
156 SVGA_STATS_TIME_VBUFDRAWELEMENTS
,
157 SVGA_STATS_TIME_VBUFRENDERALLOCVERT
,
158 SVGA_STATS_TIME_VBUFRENDERMAPVERT
,
159 SVGA_STATS_TIME_VBUFRENDERUNMAPVERT
,
160 SVGA_STATS_TIME_VBUFSUBMITSTATE
,
164 #define SVGA_STATS_PREFIX "GuestGL_"
166 #define SVGA_STATS_COUNT_NAMES \
167 SVGA_STATS_PREFIX "BlendState", \
168 SVGA_STATS_PREFIX "DepthStencilState", \
169 SVGA_STATS_PREFIX "RasterizerState", \
170 SVGA_STATS_PREFIX "Sampler", \
171 SVGA_STATS_PREFIX "SamplerView", \
172 SVGA_STATS_PREFIX "SurfaceWriteFlush", \
173 SVGA_STATS_PREFIX "TextureReadback", \
174 SVGA_STATS_PREFIX "VertexElement" \
176 #define SVGA_STATS_TIME_NAMES \
177 SVGA_STATS_PREFIX "BuffersFlush", \
178 SVGA_STATS_PREFIX "BufferTransferMap", \
179 SVGA_STATS_PREFIX "BufferTransferUnmap", \
180 SVGA_STATS_PREFIX "ContextFinish", \
181 SVGA_STATS_PREFIX "ContextFlush", \
182 SVGA_STATS_PREFIX "CreateBackedSurfaceView", \
183 SVGA_STATS_PREFIX "CreateBuffer", \
184 SVGA_STATS_PREFIX "CreateContext", \
185 SVGA_STATS_PREFIX "CreateFS", \
186 SVGA_STATS_PREFIX "CreateGS", \
187 SVGA_STATS_PREFIX "CreateSurface", \
188 SVGA_STATS_PREFIX "CreateSurfaceView", \
189 SVGA_STATS_PREFIX "CreateTexture", \
190 SVGA_STATS_PREFIX "CreateVS", \
191 SVGA_STATS_PREFIX "DefineShader", \
192 SVGA_STATS_PREFIX "DestroySurface", \
193 SVGA_STATS_PREFIX "DrawVBO", \
194 SVGA_STATS_PREFIX "DrawArrays", \
195 SVGA_STATS_PREFIX "DrawElements", \
196 SVGA_STATS_PREFIX "EmitFS", \
197 SVGA_STATS_PREFIX "EmitGS", \
198 SVGA_STATS_PREFIX "EmitVS", \
199 SVGA_STATS_PREFIX "FenceFinish", \
200 SVGA_STATS_PREFIX "GenerateIndices", \
201 SVGA_STATS_PREFIX "HWtnlDrawArrays", \
202 SVGA_STATS_PREFIX "HWtnlDrawElements", \
203 SVGA_STATS_PREFIX "HWtnlFlush", \
204 SVGA_STATS_PREFIX "HWtnlPrim", \
205 SVGA_STATS_PREFIX "PropagateSurface", \
206 SVGA_STATS_PREFIX "SetSamplerViews", \
207 SVGA_STATS_PREFIX "SurfaceFlush", \
208 SVGA_STATS_PREFIX "SwtnlDrawVBO", \
209 SVGA_STATS_PREFIX "SwtnlUpdateDraw", \
210 SVGA_STATS_PREFIX "SwtnlUpdateVDecl", \
211 SVGA_STATS_PREFIX "TextureTransferMap", \
212 SVGA_STATS_PREFIX "TextureTransferUnmap", \
213 SVGA_STATS_PREFIX "TGSIVGPU10Translate", \
214 SVGA_STATS_PREFIX "TGSIVGPU9Translate", \
215 SVGA_STATS_PREFIX "UpdateState", \
216 SVGA_STATS_PREFIX "ValidateSurfaceView", \
217 SVGA_STATS_PREFIX "VbufDrawArrays", \
218 SVGA_STATS_PREFIX "VbufDrawElements", \
219 SVGA_STATS_PREFIX "VbufRenderAllocVertices", \
220 SVGA_STATS_PREFIX "VbufRenderMapVertices", \
221 SVGA_STATS_PREFIX "VbufRenderUnmapVertices", \
222 SVGA_STATS_PREFIX "VbufSubmitState"
225 /** Opaque surface handle */
226 struct svga_winsys_surface
;
228 /** Opaque guest-backed objects */
229 struct svga_winsys_gb_shader
;
230 struct svga_winsys_gb_query
;
234 * SVGA per-context winsys interface.
236 struct svga_winsys_context
239 (*destroy
)(struct svga_winsys_context
*swc
);
242 (*reserve
)(struct svga_winsys_context
*swc
,
243 uint32_t nr_bytes
, uint32_t nr_relocs
);
246 * Returns current size of command buffer, in bytes.
249 (*get_command_buffer_size
)(struct svga_winsys_context
*swc
);
252 * Emit a relocation for a host surface.
254 * @param flags bitmask of SVGA_RELOC_* flags
256 * NOTE: Order of this call does matter. It should be the same order
257 * as relocations appear in the command buffer.
260 (*surface_relocation
)(struct svga_winsys_context
*swc
,
263 struct svga_winsys_surface
*surface
,
267 * Emit a relocation for a guest memory region.
269 * @param flags bitmask of SVGA_RELOC_* flags
271 * NOTE: Order of this call does matter. It should be the same order
272 * as relocations appear in the command buffer.
275 (*region_relocation
)(struct svga_winsys_context
*swc
,
276 struct SVGAGuestPtr
*ptr
,
277 struct svga_winsys_buffer
*buffer
,
282 * Emit a relocation for a guest-backed shader object.
284 * NOTE: Order of this call does matter. It should be the same order
285 * as relocations appear in the command buffer.
288 (*shader_relocation
)(struct svga_winsys_context
*swc
,
292 struct svga_winsys_gb_shader
*shader
,
296 * Emit a relocation for a guest-backed context.
298 * NOTE: Order of this call does matter. It should be the same order
299 * as relocations appear in the command buffer.
302 (*context_relocation
)(struct svga_winsys_context
*swc
, uint32
*cid
);
305 * Emit a relocation for a guest Memory OBject.
307 * @param flags bitmask of SVGA_RELOC_* flags
308 * @param offset_into_mob Buffer starts at this offset into the MOB.
310 * Note that not all commands accept an offset into the MOB and
311 * those commands can't use suballocated buffer pools. To trap
312 * errors from improper buffer pool usage, set the offset_into_mob
316 (*mob_relocation
)(struct svga_winsys_context
*swc
,
318 uint32
*offset_into_mob
,
319 struct svga_winsys_buffer
*buffer
,
324 * Emit a relocation for a guest-backed query object.
326 * NOTE: Order of this call does matter. It should be the same order
327 * as relocations appear in the command buffer.
330 (*query_relocation
)(struct svga_winsys_context
*swc
,
332 struct svga_winsys_gb_query
*query
);
335 * Bind queries to context.
336 * \param flags exactly one of SVGA_QUERY_FLAG_SET/REF
339 (*query_bind
)(struct svga_winsys_context
*sws
,
340 struct svga_winsys_gb_query
*query
,
344 (*commit
)(struct svga_winsys_context
*swc
);
347 (*flush
)(struct svga_winsys_context
*swc
,
348 struct pipe_fence_handle
**pfence
);
351 * Context ID used to fill in the commands
353 * Context IDs are arbitrary small non-negative integers,
354 * global to the entire SVGA device.
359 * Flags to hint the current context state
364 ** BEGIN new functions for guest-backed surfaces.
367 boolean have_gb_objects
;
370 * Map a guest-backed surface.
371 * \param flags bitmaks of PIPE_TRANSFER_x flags
373 * The surface_map() member is allowed to fail due to a
374 * shortage of command buffer space, if the
375 * PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE bit is set in flags.
376 * In that case, the caller must flush the current command
377 * buffer and reissue the map.
380 (*surface_map
)(struct svga_winsys_context
*swc
,
381 struct svga_winsys_surface
*surface
,
382 unsigned flags
, boolean
*retry
);
385 * Unmap a guest-backed surface.
386 * \param rebind returns a flag indicating whether the caller should
387 * issue a SVGA3D_BindGBSurface() call.
390 (*surface_unmap
)(struct svga_winsys_context
*swc
,
391 struct svga_winsys_surface
*surface
,
395 * Invalidate the content of this surface
398 (*surface_invalidate
)(struct svga_winsys_context
*swc
,
399 struct svga_winsys_surface
*surface
);
402 * Create and define a DX GB shader that resides in the device COTable.
403 * Caller of this function will issue the DXDefineShader command.
405 struct svga_winsys_gb_shader
*
406 (*shader_create
)(struct svga_winsys_context
*swc
,
408 SVGA3dShaderType shaderType
,
409 const uint32
*bytecode
,
413 * Destroy a DX GB shader.
414 * This function will issue the DXDestroyShader command.
417 (*shader_destroy
)(struct svga_winsys_context
*swc
,
418 struct svga_winsys_gb_shader
*shader
);
421 * Rebind a DX GB resource to a context.
422 * This is called to reference a DX GB resource in the command stream in
423 * order to page in the associated resource in case the memory has been
424 * paged out, and to fence it if necessary after command submission.
427 (*resource_rebind
)(struct svga_winsys_context
*swc
,
428 struct svga_winsys_surface
*surface
,
429 struct svga_winsys_gb_shader
*shader
,
432 /** To report perf/conformance/etc issues to the state tracker */
433 struct pipe_debug_callback
*debug_callback
;
435 /** The more recent command issued to command buffer */
436 SVGAFifo3dCmdId last_command
;
441 * SVGA per-screen winsys interface.
443 struct svga_winsys_screen
446 (*destroy
)(struct svga_winsys_screen
*sws
);
448 SVGA3dHardwareVersion
449 (*get_hw_version
)(struct svga_winsys_screen
*sws
);
452 (*get_cap
)(struct svga_winsys_screen
*sws
,
453 SVGA3dDevCapIndex index
,
454 SVGA3dDevCapResult
*result
);
457 * Create a new context.
459 * Context objects encapsulate all render state, and shader
460 * objects are per-context.
462 * Surfaces are not per-context. The same surface can be shared
463 * between multiple contexts, and surface operations can occur
466 struct svga_winsys_context
*
467 (*context_create
)(struct svga_winsys_screen
*sws
);
471 * This creates a "surface" object in the SVGA3D device.
473 * \param sws Pointer to an svga_winsys_context
474 * \param flags Device surface create flags
475 * \param format Format Device surface format
476 * \param usage Winsys usage: bitmask of SVGA_SURFACE_USAGE_x flags
477 * \param size Surface size given in device format
478 * \param numLayers Number of layers of the surface (or cube faces)
479 * \param numMipLevels Number of mipmap levels for each face
481 * Returns the surface ID (sid). Surfaces are generic
482 * containers for host VRAM objects like textures, vertex
483 * buffers, and depth/stencil buffers.
485 * Surfaces are hierarchial:
487 * - Surface may have multiple faces (for cube maps)
489 * - Each face has a list of mipmap levels
491 * - Each mipmap image may have multiple volume
492 * slices for 3D image, or multiple 2D slices for texture array.
494 * - Each slice is a 2D array of 'blocks'
496 * - Each block may be one or more pixels.
497 * (Usually 1, more for DXT or YUV formats.)
499 * Surfaces are generic host VRAM objects. The SVGA3D device
500 * may optimize surfaces according to the format they were
501 * created with, but this format does not limit the ways in
502 * which the surface may be used. For example, a depth surface
503 * can be used as a texture, or a floating point image may
504 * be used as a vertex buffer. Some surface usages may be
505 * lower performance, due to software emulation, but any
506 * usage should work with any surface.
508 struct svga_winsys_surface
*
509 (*surface_create
)(struct svga_winsys_screen
*sws
,
510 SVGA3dSurfaceFlags flags
,
511 SVGA3dSurfaceFormat format
,
516 unsigned sampleCount
);
519 * Creates a surface from a winsys handle.
520 * Used to implement pipe_screen::resource_from_handle.
522 struct svga_winsys_surface
*
523 (*surface_from_handle
)(struct svga_winsys_screen
*sws
,
524 struct winsys_handle
*whandle
,
525 SVGA3dSurfaceFormat
*format
);
528 * Get a winsys_handle from a surface.
529 * Used to implement pipe_screen::resource_get_handle.
532 (*surface_get_handle
)(struct svga_winsys_screen
*sws
,
533 struct svga_winsys_surface
*surface
,
535 struct winsys_handle
*whandle
);
538 * Whether this surface is sitting in a validate list
541 (*surface_is_flushed
)(struct svga_winsys_screen
*sws
,
542 struct svga_winsys_surface
*surface
);
545 * Reference a SVGA3D surface object. This allows sharing of a
546 * surface between different objects.
549 (*surface_reference
)(struct svga_winsys_screen
*sws
,
550 struct svga_winsys_surface
**pdst
,
551 struct svga_winsys_surface
*src
);
554 * Check if a resource (texture, buffer) of the given size
555 * and format can be created.
556 * \Return TRUE if OK, FALSE if too large.
559 (*surface_can_create
)(struct svga_winsys_screen
*sws
,
560 SVGA3dSurfaceFormat format
,
563 uint32 numMipLevels
);
566 * Buffer management. Buffer attributes are mostly fixed over its lifetime.
568 * @param usage bitmask of SVGA_BUFFER_USAGE_* flags.
570 * alignment indicates the client's alignment requirements, eg for
573 struct svga_winsys_buffer
*
574 (*buffer_create
)( struct svga_winsys_screen
*sws
,
580 * Map the entire data store of a buffer object into the client's address.
581 * usage is a bitmask of PIPE_TRANSFER_*
584 (*buffer_map
)( struct svga_winsys_screen
*sws
,
585 struct svga_winsys_buffer
*buf
,
589 (*buffer_unmap
)( struct svga_winsys_screen
*sws
,
590 struct svga_winsys_buffer
*buf
);
593 (*buffer_destroy
)( struct svga_winsys_screen
*sws
,
594 struct svga_winsys_buffer
*buf
);
598 * Reference a fence object.
601 (*fence_reference
)( struct svga_winsys_screen
*sws
,
602 struct pipe_fence_handle
**pdst
,
603 struct pipe_fence_handle
*src
);
606 * Checks whether the fence has been signalled.
607 * \param flags driver-specific meaning
608 * \return zero on success.
610 int (*fence_signalled
)( struct svga_winsys_screen
*sws
,
611 struct pipe_fence_handle
*fence
,
615 * Wait for the fence to finish.
616 * \param flags driver-specific meaning
617 * \return zero on success.
619 int (*fence_finish
)( struct svga_winsys_screen
*sws
,
620 struct pipe_fence_handle
*fence
,
625 ** BEGIN new functions for guest-backed surfaces.
628 /** Are guest-backed objects enabled? */
629 bool have_gb_objects
;
631 /** Can we do DMA with guest-backed objects enabled? */
635 * Create and define a GB shader.
637 struct svga_winsys_gb_shader
*
638 (*shader_create
)(struct svga_winsys_screen
*sws
,
639 SVGA3dShaderType shaderType
,
640 const uint32
*bytecode
,
644 * Destroy a GB shader. It's safe to call this function even
645 * if the shader is referenced in a context's command stream.
648 (*shader_destroy
)(struct svga_winsys_screen
*sws
,
649 struct svga_winsys_gb_shader
*shader
);
652 * Create and define a GB query.
654 struct svga_winsys_gb_query
*
655 (*query_create
)(struct svga_winsys_screen
*sws
, uint32 len
);
658 * Destroy a GB query.
661 (*query_destroy
)(struct svga_winsys_screen
*sws
,
662 struct svga_winsys_gb_query
*query
);
665 * Initialize the query state of the query that resides in the slot
666 * specified in offset
667 * \return zero on success.
670 (*query_init
)(struct svga_winsys_screen
*sws
,
671 struct svga_winsys_gb_query
*query
,
673 SVGA3dQueryState queryState
);
676 * Inquire for the query state and result of the query that resides
677 * in the slot specified in offset
680 (*query_get_result
)(struct svga_winsys_screen
*sws
,
681 struct svga_winsys_gb_query
*query
,
683 SVGA3dQueryState
*queryState
,
684 void *result
, uint32 resultLen
);
687 * Increment a statistic counter
690 (*stats_inc
)(enum svga_stats_count
);
693 * Push a time frame onto the stack
696 (*stats_time_push
)(enum svga_stats_time
, struct svga_winsys_stats_timeframe
*);
705 /** Have VGPU v10 hardware? */
708 /** To rebind resources at the beginnning of a new command buffer */
709 boolean need_to_rebind_resources
;
711 boolean have_generate_mipmap_cmd
;
712 boolean have_set_predication_cmd
;
713 boolean have_transfer_from_buffer_cmd
;
717 struct svga_winsys_screen
*
718 svga_winsys_screen(struct pipe_screen
*screen
);
720 struct svga_winsys_context
*
721 svga_winsys_context(struct pipe_context
*context
);
723 struct pipe_resource
*
724 svga_screen_buffer_wrap_surface(struct pipe_screen
*screen
,
725 enum SVGA3dSurfaceFormat format
,
726 struct svga_winsys_surface
*srf
);
728 struct svga_winsys_surface
*
729 svga_screen_buffer_get_winsys_surface(struct pipe_resource
*buffer
);
731 #endif /* SVGA_WINSYS_H_ */