• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**********************************************************
2  * Copyright 2008-2009 VMware, Inc.  All rights reserved.
3  *
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:
11  *
12  * The above copyright notice and this permission notice shall be
13  * included in all copies or substantial portions of the Software.
14  *
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
22  * SOFTWARE.
23  *
24  **********************************************************/
25 
26 /**
27  * @file
28  * VMware SVGA specific winsys interface.
29  *
30  * @author Jose Fonseca <jfonseca@vmware.com>
31  *
32  * Documentation taken from the VMware SVGA DDK.
33  */
34 
35 #ifndef SVGA_WINSYS_H_
36 #define SVGA_WINSYS_H_
37 
38 
39 #include "svga_types.h"
40 #include "svga_reg.h"
41 #include "svga3d_reg.h"
42 
43 #include "pipe/p_compiler.h"
44 #include "pipe/p_defines.h"
45 
46 #include "svga_mksstats.h"
47 
48 struct svga_winsys_screen;
49 struct svga_winsys_buffer;
50 struct pipe_screen;
51 struct pipe_context;
52 struct pipe_debug_callback;
53 struct pipe_fence_handle;
54 struct pipe_resource;
55 struct svga_region;
56 struct winsys_handle;
57 
58 
59 #define SVGA_BUFFER_USAGE_PINNED  (1 << 0)
60 #define SVGA_BUFFER_USAGE_WRAPPED (1 << 1)
61 #define SVGA_BUFFER_USAGE_SHADER  (1 << 2)
62 
63 /**
64  * Relocation flags to help with dirty tracking
65  * SVGA_RELOC_WRITE -   The command will cause a GPU write to this
66  *                      resource.
67  * SVGA_RELOC_READ -    The command will cause a GPU read from this
68  *                      resource.
69  * SVGA_RELOC_INTERNAL  The command will only transfer data internally
70  *                      within the resource, and optionally clear
71  *                      dirty bits
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.
75  */
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)
80 
81 #define SVGA_FENCE_FLAG_EXEC      (1 << 0)
82 #define SVGA_FENCE_FLAG_QUERY     (1 << 1)
83 
84 #define SVGA_SURFACE_USAGE_SHARED  (1 << 0)
85 #define SVGA_SURFACE_USAGE_SCANOUT (1 << 1)
86 
87 #define SVGA_QUERY_FLAG_SET        (1 << 0)
88 #define SVGA_QUERY_FLAG_REF        (1 << 1)
89 
90 #define SVGA_HINT_FLAG_CAN_PRE_FLUSH (1 << 0)  /* Can preemptively flush */
91 
92 /**
93  * SVGA mks statistics info
94  */
95 struct svga_winsys_stats_timeframe {
96    void *counterTime;
97    uint64 startTime;
98    uint64 adjustedStartTime;
99    struct svga_winsys_stats_timeframe *enclosing;
100 };
101 
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,
111    SVGA_STATS_COUNT_MAX
112 };
113 
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,
161    SVGA_STATS_TIME_MAX
162 };
163 
164 #define SVGA_STATS_PREFIX "GuestGL_"
165 
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"          \
175 
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"
223 
224 
225 /** Opaque surface handle */
226 struct svga_winsys_surface;
227 
228 /** Opaque guest-backed objects */
229 struct svga_winsys_gb_shader;
230 struct svga_winsys_gb_query;
231 
232 
233 /**
234  * SVGA per-context winsys interface.
235  */
236 struct svga_winsys_context
237 {
238    void
239    (*destroy)(struct svga_winsys_context *swc);
240 
241    void *
242    (*reserve)(struct svga_winsys_context *swc,
243 	      uint32_t nr_bytes, uint32_t nr_relocs );
244 
245    /**
246     * Returns current size of command buffer, in bytes.
247     */
248    unsigned
249    (*get_command_buffer_size)(struct svga_winsys_context *swc);
250 
251    /**
252     * Emit a relocation for a host surface.
253     *
254     * @param flags bitmask of SVGA_RELOC_* flags
255     *
256     * NOTE: Order of this call does matter. It should be the same order
257     * as relocations appear in the command buffer.
258     */
259    void
260    (*surface_relocation)(struct svga_winsys_context *swc,
261 	                 uint32 *sid,
262                          uint32 *mobid,
263 	                 struct svga_winsys_surface *surface,
264 	                 unsigned flags);
265 
266    /**
267     * Emit a relocation for a guest memory region.
268     *
269     * @param flags bitmask of SVGA_RELOC_* flags
270     *
271     * NOTE: Order of this call does matter. It should be the same order
272     * as relocations appear in the command buffer.
273     */
274    void
275    (*region_relocation)(struct svga_winsys_context *swc,
276 	                struct SVGAGuestPtr *ptr,
277 	                struct svga_winsys_buffer *buffer,
278 	                uint32 offset,
279                         unsigned flags);
280 
281    /**
282     * Emit a relocation for a guest-backed shader object.
283     *
284     * NOTE: Order of this call does matter. It should be the same order
285     * as relocations appear in the command buffer.
286     */
287    void
288    (*shader_relocation)(struct svga_winsys_context *swc,
289 	                uint32 *shid,
290 			uint32 *mobid,
291 			uint32 *offset,
292 	                struct svga_winsys_gb_shader *shader,
293                         unsigned flags);
294 
295    /**
296     * Emit a relocation for a guest-backed context.
297     *
298     * NOTE: Order of this call does matter. It should be the same order
299     * as relocations appear in the command buffer.
300     */
301    void
302    (*context_relocation)(struct svga_winsys_context *swc, uint32 *cid);
303 
304    /**
305     * Emit a relocation for a guest Memory OBject.
306     *
307     * @param flags bitmask of SVGA_RELOC_* flags
308     * @param offset_into_mob Buffer starts at this offset into the MOB.
309     *
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
313     * pointer to NULL.
314     */
315    void
316    (*mob_relocation)(struct svga_winsys_context *swc,
317 		     SVGAMobId *id,
318 		     uint32 *offset_into_mob,
319 		     struct svga_winsys_buffer *buffer,
320 		     uint32 offset,
321 		     unsigned flags);
322 
323    /**
324     * Emit a relocation for a guest-backed query object.
325     *
326     * NOTE: Order of this call does matter. It should be the same order
327     * as relocations appear in the command buffer.
328     */
329    void
330    (*query_relocation)(struct svga_winsys_context *swc,
331 	               SVGAMobId *id,
332 	               struct svga_winsys_gb_query *query);
333 
334    /**
335     * Bind queries to context.
336     * \param flags  exactly one of SVGA_QUERY_FLAG_SET/REF
337     */
338    enum pipe_error
339    (*query_bind)(struct svga_winsys_context *sws,
340                  struct svga_winsys_gb_query *query,
341                  unsigned flags);
342 
343    void
344    (*commit)(struct svga_winsys_context *swc);
345 
346    enum pipe_error
347    (*flush)(struct svga_winsys_context *swc,
348 	    struct pipe_fence_handle **pfence);
349 
350    /**
351     * Context ID used to fill in the commands
352     *
353     * Context IDs are arbitrary small non-negative integers,
354     * global to the entire SVGA device.
355     */
356    uint32 cid;
357 
358    /**
359     * Flags to hint the current context state
360     */
361    uint32 hints;
362 
363    /**
364     ** BEGIN new functions for guest-backed surfaces.
365     **/
366 
367    boolean have_gb_objects;
368 
369    /**
370     * Map a guest-backed surface.
371     * \param flags  bitmaks of PIPE_TRANSFER_x flags
372     *
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.
378     */
379    void *
380    (*surface_map)(struct svga_winsys_context *swc,
381                   struct svga_winsys_surface *surface,
382                   unsigned flags, boolean *retry);
383 
384    /**
385     * Unmap a guest-backed surface.
386     * \param rebind  returns a flag indicating whether the caller should
387     *                issue a SVGA3D_BindGBSurface() call.
388     */
389    void
390    (*surface_unmap)(struct svga_winsys_context *swc,
391                     struct svga_winsys_surface *surface,
392                     boolean *rebind);
393 
394    /**
395     * Create and define a DX GB shader that resides in the device COTable.
396     * Caller of this function will issue the DXDefineShader command.
397     */
398    struct svga_winsys_gb_shader *
399    (*shader_create)(struct svga_winsys_context *swc,
400                     uint32 shaderId,
401                     SVGA3dShaderType shaderType,
402                     const uint32 *bytecode,
403                     uint32 bytecodeLen);
404 
405    /**
406     * Destroy a DX GB shader.
407     * This function will issue the DXDestroyShader command.
408     */
409    void
410    (*shader_destroy)(struct svga_winsys_context *swc,
411                      struct svga_winsys_gb_shader *shader);
412 
413    /**
414     * Rebind a DX GB resource to a context.
415     * This is called to reference a DX GB resource in the command stream in
416     * order to page in the associated resource in case the memory has been
417     * paged out, and to fence it if necessary after command submission.
418     */
419    enum pipe_error
420    (*resource_rebind)(struct svga_winsys_context *swc,
421                       struct svga_winsys_surface *surface,
422                       struct svga_winsys_gb_shader *shader,
423                       unsigned flags);
424 
425    /** To report perf/conformance/etc issues to the state tracker */
426    struct pipe_debug_callback *debug_callback;
427 
428    /** The more recent command issued to command buffer */
429    SVGAFifo3dCmdId last_command;
430 };
431 
432 
433 /**
434  * SVGA per-screen winsys interface.
435  */
436 struct svga_winsys_screen
437 {
438    void
439    (*destroy)(struct svga_winsys_screen *sws);
440 
441    SVGA3dHardwareVersion
442    (*get_hw_version)(struct svga_winsys_screen *sws);
443 
444    boolean
445    (*get_cap)(struct svga_winsys_screen *sws,
446               SVGA3dDevCapIndex index,
447               SVGA3dDevCapResult *result);
448 
449    /**
450     * Create a new context.
451     *
452     * Context objects encapsulate all render state, and shader
453     * objects are per-context.
454     *
455     * Surfaces are not per-context. The same surface can be shared
456     * between multiple contexts, and surface operations can occur
457     * without a context.
458     */
459    struct svga_winsys_context *
460    (*context_create)(struct svga_winsys_screen *sws);
461 
462 
463    /**
464     * This creates a "surface" object in the SVGA3D device.
465     *
466     * \param sws Pointer to an svga_winsys_context
467     * \param flags Device surface create flags
468     * \param format Format Device surface format
469     * \param usage Winsys usage: bitmask of SVGA_SURFACE_USAGE_x flags
470     * \param size Surface size given in device format
471     * \param numLayers Number of layers of the surface (or cube faces)
472     * \param numMipLevels Number of mipmap levels for each face
473     *
474     * Returns the surface ID (sid). Surfaces are generic
475     * containers for host VRAM objects like textures, vertex
476     * buffers, and depth/stencil buffers.
477     *
478     * Surfaces are hierarchial:
479     *
480     * - Surface may have multiple faces (for cube maps)
481     *
482     * - Each face has a list of mipmap levels
483     *
484     * - Each mipmap image may have multiple volume
485     *   slices for 3D image, or multiple 2D slices for texture array.
486     *
487     * - Each slice is a 2D array of 'blocks'
488     *
489     * - Each block may be one or more pixels.
490     *   (Usually 1, more for DXT or YUV formats.)
491     *
492     * Surfaces are generic host VRAM objects. The SVGA3D device
493     * may optimize surfaces according to the format they were
494     * created with, but this format does not limit the ways in
495     * which the surface may be used. For example, a depth surface
496     * can be used as a texture, or a floating point image may
497     * be used as a vertex buffer. Some surface usages may be
498     * lower performance, due to software emulation, but any
499     * usage should work with any surface.
500     */
501    struct svga_winsys_surface *
502    (*surface_create)(struct svga_winsys_screen *sws,
503                      SVGA3dSurfaceFlags flags,
504                      SVGA3dSurfaceFormat format,
505                      unsigned usage,
506                      SVGA3dSize size,
507                      uint32 numLayers,
508                      uint32 numMipLevels,
509                      unsigned sampleCount);
510 
511    /**
512     * Creates a surface from a winsys handle.
513     * Used to implement pipe_screen::resource_from_handle.
514     */
515    struct svga_winsys_surface *
516    (*surface_from_handle)(struct svga_winsys_screen *sws,
517                           struct winsys_handle *whandle,
518                           SVGA3dSurfaceFormat *format);
519 
520    /**
521     * Get a winsys_handle from a surface.
522     * Used to implement pipe_screen::resource_get_handle.
523     */
524    boolean
525    (*surface_get_handle)(struct svga_winsys_screen *sws,
526                          struct svga_winsys_surface *surface,
527                          unsigned stride,
528                          struct winsys_handle *whandle);
529 
530    /**
531     * Whether this surface is sitting in a validate list
532     */
533    boolean
534    (*surface_is_flushed)(struct svga_winsys_screen *sws,
535                          struct svga_winsys_surface *surface);
536 
537    /**
538     * Reference a SVGA3D surface object. This allows sharing of a
539     * surface between different objects.
540     */
541    void
542    (*surface_reference)(struct svga_winsys_screen *sws,
543 			struct svga_winsys_surface **pdst,
544 			struct svga_winsys_surface *src);
545 
546    /**
547     * Check if a resource (texture, buffer) of the given size
548     * and format can be created.
549     * \Return TRUE if OK, FALSE if too large.
550     */
551    boolean
552    (*surface_can_create)(struct svga_winsys_screen *sws,
553                          SVGA3dSurfaceFormat format,
554                          SVGA3dSize size,
555                          uint32 numLayers,
556                          uint32 numMipLevels);
557 
558    /**
559     * Invalidate the content of this surface
560     */
561    void
562    (*surface_invalidate)(struct svga_winsys_screen *sws,
563                          struct svga_winsys_surface *surface);
564 
565 
566    /**
567     * Buffer management. Buffer attributes are mostly fixed over its lifetime.
568     *
569     * @param usage bitmask of SVGA_BUFFER_USAGE_* flags.
570     *
571     * alignment indicates the client's alignment requirements, eg for
572     * SSE instructions.
573     */
574    struct svga_winsys_buffer *
575    (*buffer_create)( struct svga_winsys_screen *sws,
576 	             unsigned alignment,
577 	             unsigned usage,
578 	             unsigned size );
579 
580    /**
581     * Map the entire data store of a buffer object into the client's address.
582     * usage is a bitmask of PIPE_TRANSFER_*
583     */
584    void *
585    (*buffer_map)( struct svga_winsys_screen *sws,
586 	          struct svga_winsys_buffer *buf,
587 		  unsigned usage );
588 
589    void
590    (*buffer_unmap)( struct svga_winsys_screen *sws,
591                     struct svga_winsys_buffer *buf );
592 
593    void
594    (*buffer_destroy)( struct svga_winsys_screen *sws,
595 	              struct svga_winsys_buffer *buf );
596 
597 
598    /**
599     * Reference a fence object.
600     */
601    void
602    (*fence_reference)( struct svga_winsys_screen *sws,
603                        struct pipe_fence_handle **pdst,
604                        struct pipe_fence_handle *src );
605 
606    /**
607     * Checks whether the fence has been signalled.
608     * \param flags  driver-specific meaning
609     * \return zero on success.
610     */
611    int (*fence_signalled)( struct svga_winsys_screen *sws,
612                            struct pipe_fence_handle *fence,
613                            unsigned flag );
614 
615    /**
616     * Wait for the fence to finish.
617     * \param flags  driver-specific meaning
618     * \return zero on success.
619     */
620    int (*fence_finish)( struct svga_winsys_screen *sws,
621                         struct pipe_fence_handle *fence,
622                         unsigned flag );
623 
624 
625    /**
626     ** BEGIN new functions for guest-backed surfaces.
627     **/
628 
629    /** Are guest-backed objects enabled? */
630    bool have_gb_objects;
631 
632    /** Can we do DMA with guest-backed objects enabled? */
633    bool have_gb_dma;
634 
635    /**
636     * Create and define a GB shader.
637     */
638    struct svga_winsys_gb_shader *
639    (*shader_create)(struct svga_winsys_screen *sws,
640 		    SVGA3dShaderType shaderType,
641 		    const uint32 *bytecode,
642 		    uint32 bytecodeLen);
643 
644    /**
645     * Destroy a GB shader. It's safe to call this function even
646     * if the shader is referenced in a context's command stream.
647     */
648    void
649    (*shader_destroy)(struct svga_winsys_screen *sws,
650 		     struct svga_winsys_gb_shader *shader);
651 
652    /**
653     * Create and define a GB query.
654     */
655    struct svga_winsys_gb_query *
656    (*query_create)(struct svga_winsys_screen *sws, uint32 len);
657 
658    /**
659     * Destroy a GB query.
660     */
661    void
662    (*query_destroy)(struct svga_winsys_screen *sws,
663 		    struct svga_winsys_gb_query *query);
664 
665    /**
666     * Initialize the query state of the query that resides in the slot
667     * specified in offset
668     * \return zero on success.
669     */
670    int
671    (*query_init)(struct svga_winsys_screen *sws,
672                        struct svga_winsys_gb_query *query,
673                        unsigned offset,
674                        SVGA3dQueryState queryState);
675 
676    /**
677     * Inquire for the query state and result of the query that resides
678     * in the slot specified in offset
679     */
680    void
681    (*query_get_result)(struct svga_winsys_screen *sws,
682                        struct svga_winsys_gb_query *query,
683                        unsigned offset,
684                        SVGA3dQueryState *queryState,
685                        void *result, uint32 resultLen);
686 
687    /**
688     * Increment a statistic counter
689     */
690    void
691    (*stats_inc)(enum svga_stats_count);
692 
693    /**
694     * Push a time frame onto the stack
695     */
696    void
697    (*stats_time_push)(enum svga_stats_time, struct svga_winsys_stats_timeframe *);
698 
699    /**
700     * Pop a time frame.
701     */
702    void
703    (*stats_time_pop)();
704 
705 
706    /** Have VGPU v10 hardware? */
707    boolean have_vgpu10;
708 
709    /** To rebind resources at the beginnning of a new command buffer */
710    boolean need_to_rebind_resources;
711 
712    boolean have_generate_mipmap_cmd;
713    boolean have_set_predication_cmd;
714    boolean have_transfer_from_buffer_cmd;
715 };
716 
717 
718 struct svga_winsys_screen *
719 svga_winsys_screen(struct pipe_screen *screen);
720 
721 struct svga_winsys_context *
722 svga_winsys_context(struct pipe_context *context);
723 
724 struct pipe_resource *
725 svga_screen_buffer_wrap_surface(struct pipe_screen *screen,
726 				enum SVGA3dSurfaceFormat format,
727 				struct svga_winsys_surface *srf);
728 
729 struct svga_winsys_surface *
730 svga_screen_buffer_get_winsys_surface(struct pipe_resource *buffer);
731 
732 #endif /* SVGA_WINSYS_H_ */
733