• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2008-2024 Broadcom. All Rights Reserved.
3  * The term “Broadcom” refers to Broadcom Inc.
4  * and/or its subsidiaries.
5  * SPDX-License-Identifier: MIT
6  */
7 
8 /**
9  * @file
10  * VMware SVGA specific winsys interface.
11  *
12  * @author Jose Fonseca <jfonseca@vmware.com>
13  *
14  * Documentation taken from the VMware SVGA DDK.
15  */
16 
17 #ifndef SVGA_WINSYS_H_
18 #define SVGA_WINSYS_H_
19 
20 #include "svga3d_types.h"
21 #include "svga_reg.h"
22 #include "svga3d_reg.h"
23 
24 #include "util/compiler.h"
25 #include "pipe/p_defines.h"
26 
27 #include "svga_mksstats.h"
28 
29 struct svga_winsys_screen;
30 struct svga_winsys_buffer;
31 struct pipe_screen;
32 struct pipe_context;
33 struct util_debug_callback;
34 struct pipe_fence_handle;
35 struct pipe_resource;
36 struct svga_region;
37 struct winsys_handle;
38 
39 
40 #define SVGA_BUFFER_USAGE_PINNED  (1 << 0)
41 #define SVGA_BUFFER_USAGE_WRAPPED (1 << 1)
42 #define SVGA_BUFFER_USAGE_SHADER  (1 << 2)
43 
44 /**
45  * Relocation flags to help with dirty tracking
46  * SVGA_RELOC_WRITE -   The command will cause a GPU write to this
47  *                      resource.
48  * SVGA_RELOC_READ -    The command will cause a GPU read from this
49  *                      resource.
50  * SVGA_RELOC_INTERNAL  The command will only transfer data internally
51  *                      within the resource, and optionally clear
52  *                      dirty bits
53  * SVGA_RELOC_DMA -     Only set for resource buffer DMA uploads for winsys
54  *                      implementations that want to track the amount
55  *                      of such data referenced in the command stream.
56  */
57 #define SVGA_RELOC_WRITE          (1 << 0)
58 #define SVGA_RELOC_READ           (1 << 1)
59 #define SVGA_RELOC_INTERNAL       (1 << 2)
60 #define SVGA_RELOC_DMA            (1 << 3)
61 
62 #define SVGA_FENCE_FLAG_EXEC      (1 << 0)
63 #define SVGA_FENCE_FLAG_QUERY     (1 << 1)
64 
65 #define SVGA_SURFACE_USAGE_SHARED   (1 << 0)
66 #define SVGA_SURFACE_USAGE_SCANOUT  (1 << 1)
67 #define SVGA_SURFACE_USAGE_COHERENT (1 << 2)
68 
69 #define SVGA_QUERY_FLAG_SET        (1 << 0)
70 #define SVGA_QUERY_FLAG_REF        (1 << 1)
71 
72 #define SVGA_HINT_FLAG_CAN_PRE_FLUSH   (1 << 0)  /* Can preemptively flush */
73 #define SVGA_HINT_FLAG_EXPORT_FENCE_FD (1 << 1)  /* Export a Fence FD */
74 
75 /**
76  * SVGA mks statistics info
77  */
78 struct svga_winsys_stats_timeframe {
79    void *counterTime;
80    uint64 startTime;
81    uint64 adjustedStartTime;
82    struct svga_winsys_stats_timeframe *enclosing;
83 
84    struct svga_winsys_screen *sws;
85    int32 slot;
86 };
87 
88 enum svga_stats_count {
89    SVGA_STATS_COUNT_BLENDSTATE,
90    SVGA_STATS_COUNT_BLITBLITTERCOPY,
91    SVGA_STATS_COUNT_DEPTHSTENCILSTATE,
92    SVGA_STATS_COUNT_RASTERIZERSTATE,
93    SVGA_STATS_COUNT_RAWBUFFERSRVIEW,
94    SVGA_STATS_COUNT_SAMPLER,
95    SVGA_STATS_COUNT_SAMPLERVIEW,
96    SVGA_STATS_COUNT_SURFACEWRITEFLUSH,
97    SVGA_STATS_COUNT_TEXREADBACK,
98    SVGA_STATS_COUNT_VERTEXELEMENT,
99    SVGA_STATS_COUNT_MAX
100 };
101 
102 enum svga_stats_time {
103    SVGA_STATS_TIME_BLIT,
104    SVGA_STATS_TIME_BLITBLITTER,
105    SVGA_STATS_TIME_BLITFALLBACK,
106    SVGA_STATS_TIME_BUFFERSFLUSH,
107    SVGA_STATS_TIME_BUFFERTRANSFERMAP,
108    SVGA_STATS_TIME_BUFFERTRANSFERUNMAP,
109    SVGA_STATS_TIME_CONTEXTFINISH,
110    SVGA_STATS_TIME_CONTEXTFLUSH,
111    SVGA_STATS_TIME_COPYREGION,
112    SVGA_STATS_TIME_COPYREGIONFALLBACK,
113    SVGA_STATS_TIME_CREATEBACKEDSURFACEVIEW,
114    SVGA_STATS_TIME_CREATEBUFFER,
115    SVGA_STATS_TIME_CREATECONTEXT,
116    SVGA_STATS_TIME_CREATECS,
117    SVGA_STATS_TIME_CREATEFS,
118    SVGA_STATS_TIME_CREATEGS,
119    SVGA_STATS_TIME_CREATESURFACE,
120    SVGA_STATS_TIME_CREATESURFACEVIEW,
121    SVGA_STATS_TIME_CREATETCS,
122    SVGA_STATS_TIME_CREATETES,
123    SVGA_STATS_TIME_CREATETEXTURE,
124    SVGA_STATS_TIME_CREATEVS,
125    SVGA_STATS_TIME_DEFINESHADER,
126    SVGA_STATS_TIME_DESTROYSURFACE,
127    SVGA_STATS_TIME_DRAWVBO,
128    SVGA_STATS_TIME_DRAWARRAYS,
129    SVGA_STATS_TIME_DRAWELEMENTS,
130    SVGA_STATS_TIME_EMITCS,
131    SVGA_STATS_TIME_EMITFS,
132    SVGA_STATS_TIME_EMITGS,
133    SVGA_STATS_TIME_EMITRAWBUFFER,
134    SVGA_STATS_TIME_EMITTCS,
135    SVGA_STATS_TIME_EMITTES,
136    SVGA_STATS_TIME_EMITVS,
137    SVGA_STATS_TIME_EMULATESURFACEVIEW,
138    SVGA_STATS_TIME_FENCEFINISH,
139    SVGA_STATS_TIME_GENERATEINDICES,
140    SVGA_STATS_TIME_HWTNLDRAWARRAYS,
141    SVGA_STATS_TIME_HWTNLDRAWELEMENTS,
142    SVGA_STATS_TIME_HWTNLFLUSH,
143    SVGA_STATS_TIME_HWTNLPRIM,
144    SVGA_STATS_TIME_LAUNCHGRID,
145    SVGA_STATS_TIME_PROPAGATESURFACE,
146    SVGA_STATS_TIME_SETSAMPLERVIEWS,
147    SVGA_STATS_TIME_SURFACEFLUSH,
148    SVGA_STATS_TIME_SWTNLDRAWVBO,
149    SVGA_STATS_TIME_SWTNLUPDATEDRAW,
150    SVGA_STATS_TIME_SWTNLUPDATEVDECL,
151    SVGA_STATS_TIME_TEXTRANSFERMAP,
152    SVGA_STATS_TIME_TEXTRANSFERUNMAP,
153    SVGA_STATS_TIME_TGSIVGPU10TRANSLATE,
154    SVGA_STATS_TIME_TGSIVGPU9TRANSLATE,
155    SVGA_STATS_TIME_UPDATECSUAV,
156    SVGA_STATS_TIME_UPDATESTATE,
157    SVGA_STATS_TIME_UPDATEUAV,
158    SVGA_STATS_TIME_VALIDATESURFACEVIEW,
159    SVGA_STATS_TIME_VBUFDRAWARRAYS,
160    SVGA_STATS_TIME_VBUFDRAWELEMENTS,
161    SVGA_STATS_TIME_VBUFRENDERALLOCVERT,
162    SVGA_STATS_TIME_VBUFRENDERMAPVERT,
163    SVGA_STATS_TIME_VBUFRENDERUNMAPVERT,
164    SVGA_STATS_TIME_VBUFSUBMITSTATE,
165    SVGA_STATS_TIME_MAX
166 };
167 
168 #define SVGA_STATS_PREFIX "GuestGL_"
169 
170 #define SVGA_STATS_COUNT_NAMES                \
171    SVGA_STATS_PREFIX "BlendState",            \
172    SVGA_STATS_PREFIX "BlitBlitterCopy",       \
173    SVGA_STATS_PREFIX "DepthStencilState",     \
174    SVGA_STATS_PREFIX "RasterizerState",       \
175    SVGA_STATS_PREFIX "RawBufferSRView",       \
176    SVGA_STATS_PREFIX "Sampler",               \
177    SVGA_STATS_PREFIX "SamplerView",           \
178    SVGA_STATS_PREFIX "SurfaceWriteFlush",     \
179    SVGA_STATS_PREFIX "TextureReadback",       \
180    SVGA_STATS_PREFIX "VertexElement"          \
181 
182 #define SVGA_STATS_TIME_NAMES                       \
183    SVGA_STATS_PREFIX "Blit",                        \
184    SVGA_STATS_PREFIX "BlitBlitter",                 \
185    SVGA_STATS_PREFIX "BlitFallback",                \
186    SVGA_STATS_PREFIX "BuffersFlush",                \
187    SVGA_STATS_PREFIX "BufferTransferMap",           \
188    SVGA_STATS_PREFIX "BufferTransferUnmap",         \
189    SVGA_STATS_PREFIX "ContextFinish",               \
190    SVGA_STATS_PREFIX "ContextFlush",                \
191    SVGA_STATS_PREFIX "CopyRegion",                  \
192    SVGA_STATS_PREFIX "CopyRegionFallback",          \
193    SVGA_STATS_PREFIX "CreateBackedSurfaceView",     \
194    SVGA_STATS_PREFIX "CreateBuffer",                \
195    SVGA_STATS_PREFIX "CreateContext",               \
196    SVGA_STATS_PREFIX "CreateCS",                    \
197    SVGA_STATS_PREFIX "CreateFS",                    \
198    SVGA_STATS_PREFIX "CreateGS",                    \
199    SVGA_STATS_PREFIX "CreateSurface",               \
200    SVGA_STATS_PREFIX "CreateSurfaceView",           \
201    SVGA_STATS_PREFIX "CreateTCS",                   \
202    SVGA_STATS_PREFIX "CreateTES",                   \
203    SVGA_STATS_PREFIX "CreateTexture",               \
204    SVGA_STATS_PREFIX "CreateVS",                    \
205    SVGA_STATS_PREFIX "DefineShader",                \
206    SVGA_STATS_PREFIX "DestroySurface",              \
207    SVGA_STATS_PREFIX "DrawVBO",                     \
208    SVGA_STATS_PREFIX "DrawArrays",                  \
209    SVGA_STATS_PREFIX "DrawElements",                \
210    SVGA_STATS_PREFIX "EmitCS",                      \
211    SVGA_STATS_PREFIX "EmitFS",                      \
212    SVGA_STATS_PREFIX "EmitGS",                      \
213    SVGA_STATS_PREFIX "EmitRawBuffer",               \
214    SVGA_STATS_PREFIX "EmitTCS",                     \
215    SVGA_STATS_PREFIX "EmitTES",                     \
216    SVGA_STATS_PREFIX "EmitVS",                      \
217    SVGA_STATS_PREFIX "EmulateSurfaceView",          \
218    SVGA_STATS_PREFIX "FenceFinish",                 \
219    SVGA_STATS_PREFIX "GenerateIndices",             \
220    SVGA_STATS_PREFIX "HWtnlDrawArrays",             \
221    SVGA_STATS_PREFIX "HWtnlDrawElements",           \
222    SVGA_STATS_PREFIX "HWtnlFlush",                  \
223    SVGA_STATS_PREFIX "HWtnlPrim",                   \
224    SVGA_STATS_PREFIX "LaunchGrid",                  \
225    SVGA_STATS_PREFIX "PropagateSurface",            \
226    SVGA_STATS_PREFIX "SetSamplerViews",             \
227    SVGA_STATS_PREFIX "SurfaceFlush",                \
228    SVGA_STATS_PREFIX "SwtnlDrawVBO",                \
229    SVGA_STATS_PREFIX "SwtnlUpdateDraw",             \
230    SVGA_STATS_PREFIX "SwtnlUpdateVDecl",            \
231    SVGA_STATS_PREFIX "TextureTransferMap",          \
232    SVGA_STATS_PREFIX "TextureTransferUnmap",        \
233    SVGA_STATS_PREFIX "TGSIVGPU10Translate",         \
234    SVGA_STATS_PREFIX "TGSIVGPU9Translate",          \
235    SVGA_STATS_PREFIX "UpdateCSUAV",                 \
236    SVGA_STATS_PREFIX "UpdateState",                 \
237    SVGA_STATS_PREFIX "UpdateUAV",                   \
238    SVGA_STATS_PREFIX "ValidateSurfaceView",         \
239    SVGA_STATS_PREFIX "VbufDrawArrays",              \
240    SVGA_STATS_PREFIX "VbufDrawElements",            \
241    SVGA_STATS_PREFIX "VbufRenderAllocVertices",     \
242    SVGA_STATS_PREFIX "VbufRenderMapVertices",       \
243    SVGA_STATS_PREFIX "VbufRenderUnmapVertices",     \
244    SVGA_STATS_PREFIX "VbufSubmitState"
245 
246 
247 /** Opaque surface handle */
248 struct svga_winsys_surface;
249 
250 /** Opaque guest-backed objects */
251 struct svga_winsys_gb_shader;
252 struct svga_winsys_gb_query;
253 
254 
255 /**
256  * SVGA per-context winsys interface.
257  */
258 struct svga_winsys_context
259 {
260    void
261    (*destroy)(struct svga_winsys_context *swc);
262 
263    void *
264    (*reserve)(struct svga_winsys_context *swc,
265               uint32_t nr_bytes, uint32_t nr_relocs );
266 
267    /**
268     * Returns current size of command buffer, in bytes.
269     */
270    unsigned
271    (*get_command_buffer_size)(struct svga_winsys_context *swc);
272 
273    /**
274     * Emit a relocation for a host surface.
275     *
276     * @param flags bitmask of SVGA_RELOC_* flags
277     *
278     * NOTE: Order of this call does matter. It should be the same order
279     * as relocations appear in the command buffer.
280     */
281    void
282    (*surface_relocation)(struct svga_winsys_context *swc,
283                          uint32 *sid,
284                          uint32 *mobid,
285                          struct svga_winsys_surface *surface,
286                          unsigned flags);
287 
288    /**
289     * Emit a relocation for a guest memory region.
290     *
291     * @param flags bitmask of SVGA_RELOC_* flags
292     *
293     * NOTE: Order of this call does matter. It should be the same order
294     * as relocations appear in the command buffer.
295     */
296    void
297    (*region_relocation)(struct svga_winsys_context *swc,
298                         struct SVGAGuestPtr *ptr,
299                         struct svga_winsys_buffer *buffer,
300                         uint32 offset,
301                         unsigned flags);
302 
303    /**
304     * Emit a relocation for a guest-backed shader object.
305     *
306     * NOTE: Order of this call does matter. It should be the same order
307     * as relocations appear in the command buffer.
308     */
309    void
310    (*shader_relocation)(struct svga_winsys_context *swc,
311                         uint32 *shid,
312                         uint32 *mobid,
313                         uint32 *offset,
314                         struct svga_winsys_gb_shader *shader,
315                         unsigned flags);
316 
317    /**
318     * Emit a relocation for a guest-backed context.
319     *
320     * NOTE: Order of this call does matter. It should be the same order
321     * as relocations appear in the command buffer.
322     */
323    void
324    (*context_relocation)(struct svga_winsys_context *swc, uint32 *cid);
325 
326    /**
327     * Emit a relocation for a guest Memory OBject.
328     *
329     * @param flags bitmask of SVGA_RELOC_* flags
330     * @param offset_into_mob Buffer starts at this offset into the MOB.
331     *
332     * Note that not all commands accept an offset into the MOB and
333     * those commands can't use suballocated buffer pools. To trap
334     * errors from improper buffer pool usage, set the offset_into_mob
335     * pointer to NULL.
336     */
337    void
338    (*mob_relocation)(struct svga_winsys_context *swc,
339                      SVGAMobId *id,
340                      uint32 *offset_into_mob,
341                      struct svga_winsys_buffer *buffer,
342                      uint32 offset,
343                      unsigned flags);
344 
345    /**
346     * Emit a relocation for a guest-backed query object.
347     *
348     * NOTE: Order of this call does matter. It should be the same order
349     * as relocations appear in the command buffer.
350     */
351    void
352    (*query_relocation)(struct svga_winsys_context *swc,
353                        SVGAMobId *id,
354                        struct svga_winsys_gb_query *query);
355 
356    /**
357     * Bind queries to context.
358     * \param flags  exactly one of SVGA_QUERY_FLAG_SET/REF
359     */
360    enum pipe_error
361    (*query_bind)(struct svga_winsys_context *sws,
362                  struct svga_winsys_gb_query *query,
363                  unsigned flags);
364 
365    void
366    (*commit)(struct svga_winsys_context *swc);
367 
368    enum pipe_error
369    (*flush)(struct svga_winsys_context *swc,
370             struct pipe_fence_handle **pfence);
371 
372    /**
373     * Context ID used to fill in the commands
374     *
375     * Context IDs are arbitrary small non-negative integers,
376     * global to the entire SVGA device.
377     */
378    uint32 cid;
379 
380    /**
381     * Flags to hint the current context state
382     */
383    uint32 hints;
384 
385    /**
386     * File descriptor for imported fence
387     */
388    int32 imported_fence_fd;
389 
390    /**
391     ** BEGIN new functions for guest-backed surfaces.
392     **/
393 
394    bool have_gb_objects;
395    bool force_coherent;
396 
397    /**
398     * Map a guest-backed surface.
399     * \param swc The winsys context
400     * \param surface The surface to map
401     * \param flags  bitmask of PIPE_MAP_x flags
402     * \param retry Whether to flush and retry the map
403     * \param rebind Whether to issue an immediate rebind and flush.
404     *
405     * The surface_map() member is allowed to fail due to a
406     * shortage of command buffer space, if the
407     * PIPE_MAP_DISCARD_WHOLE_RESOURCE bit is set in flags.
408     * In that case, the caller must flush the current command
409     * buffer and reissue the map.
410     */
411    void *
412    (*surface_map)(struct svga_winsys_context *swc,
413                   struct svga_winsys_surface *surface,
414                   unsigned flags, bool *retry,
415                   bool *rebind);
416 
417    /**
418     * Unmap a guest-backed surface.
419     * \param rebind  returns a flag indicating whether the caller should
420     *                issue a SVGA3D_BindGBSurface() call.
421     */
422    void
423    (*surface_unmap)(struct svga_winsys_context *swc,
424                     struct svga_winsys_surface *surface,
425                     bool *rebind);
426 
427    /**
428     * Create and define a DX GB shader that resides in the device COTable.
429     * Caller of this function will issue the DXDefineShader command.
430     */
431    struct svga_winsys_gb_shader *
432    (*shader_create)(struct svga_winsys_context *swc,
433                     uint32 shaderId,
434                     SVGA3dShaderType shaderType,
435                     const uint32 *bytecode,
436                     uint32 bytecodeLen,
437                     const SVGA3dDXShaderSignatureHeader *sgnInfo,
438                     uint32 sgnLen);
439 
440    /**
441     * Destroy a DX GB shader.
442     * This function will issue the DXDestroyShader command.
443     */
444    void
445    (*shader_destroy)(struct svga_winsys_context *swc,
446                      struct svga_winsys_gb_shader *shader);
447 
448    /**
449     * Rebind a DX GB resource to a context.
450     * This is called to reference a DX GB resource in the command stream in
451     * order to page in the associated resource in case the memory has been
452     * paged out, and to fence it if necessary after command submission.
453     */
454    enum pipe_error
455    (*resource_rebind)(struct svga_winsys_context *swc,
456                       struct svga_winsys_surface *surface,
457                       struct svga_winsys_gb_shader *shader,
458                       unsigned flags);
459 
460    /** To report perf/conformance/etc issues to the gallium frontend */
461    struct util_debug_callback *debug_callback;
462 
463    /** The more recent command issued to command buffer */
464    SVGAFifo3dCmdId last_command;
465 
466    /** For HUD queries */
467    uint64_t num_commands;
468    uint64_t num_command_buffers;
469    uint64_t num_draw_commands;
470    uint64_t num_shader_reloc;
471    uint64_t num_surf_reloc;
472 
473    /* Whether we are in retry processing */
474    unsigned int in_retry;
475 };
476 
477 
478 /**
479  * SVGA per-screen winsys interface.
480  */
481 struct svga_winsys_screen
482 {
483    void
484    (*destroy)(struct svga_winsys_screen *sws);
485 
486    SVGA3dHardwareVersion
487    (*get_hw_version)(struct svga_winsys_screen *sws);
488 
489    int
490    (*get_fd)(struct svga_winsys_screen *sws);
491 
492    bool
493    (*get_cap)(struct svga_winsys_screen *sws,
494               SVGA3dDevCapIndex index,
495               SVGA3dDevCapResult *result);
496 
497    /**
498     * Create a new context.
499     *
500     * Context objects encapsulate all render state, and shader
501     * objects are per-context.
502     *
503     * Surfaces are not per-context. The same surface can be shared
504     * between multiple contexts, and surface operations can occur
505     * without a context.
506     */
507    struct svga_winsys_context *
508    (*context_create)(struct svga_winsys_screen *sws);
509 
510    /**
511     * This creates a "surface" object in the SVGA3D device.
512     *
513     * \param sws Pointer to an svga_winsys_context
514     * \param flags Device surface create flags
515     * \param format Format Device surface format
516     * \param usage Winsys usage: bitmask of SVGA_SURFACE_USAGE_x flags
517     * \param size Surface size given in device format
518     * \param numLayers Number of layers of the surface (or cube faces)
519     * \param numMipLevels Number of mipmap levels for each face
520     *
521     * Returns the surface ID (sid). Surfaces are generic
522     * containers for host VRAM objects like textures, vertex
523     * buffers, and depth/stencil buffers.
524     *
525     * Surfaces are hierarchial:
526     *
527     * - Surface may have multiple faces (for cube maps)
528     *
529     * - Each face has a list of mipmap levels
530     *
531     * - Each mipmap image may have multiple volume
532     *   slices for 3D image, or multiple 2D slices for texture array.
533     *
534     * - Each slice is a 2D array of 'blocks'
535     *
536     * - Each block may be one or more pixels.
537     *   (Usually 1, more for DXT or YUV formats.)
538     *
539     * Surfaces are generic host VRAM objects. The SVGA3D device
540     * may optimize surfaces according to the format they were
541     * created with, but this format does not limit the ways in
542     * which the surface may be used. For example, a depth surface
543     * can be used as a texture, or a floating point image may
544     * be used as a vertex buffer. Some surface usages may be
545     * lower performance, due to software emulation, but any
546     * usage should work with any surface.
547     */
548    struct svga_winsys_surface *
549    (*surface_create)(struct svga_winsys_screen *sws,
550                      SVGA3dSurfaceAllFlags flags,
551                      SVGA3dSurfaceFormat format,
552                      unsigned usage,
553                      SVGA3dSize size,
554                      uint32 numLayers,
555                      uint32 numMipLevels,
556                      unsigned sampleCount);
557 
558    /**
559     * Creates a surface from a winsys handle.
560     * Used to implement pipe_screen::resource_from_handle.
561     */
562    struct svga_winsys_surface *
563    (*surface_from_handle)(struct svga_winsys_screen *sws,
564                           struct winsys_handle *whandle,
565                           SVGA3dSurfaceFormat *format);
566 
567    /**
568     * Get a winsys_handle from a surface.
569     * Used to implement pipe_screen::resource_get_handle.
570     */
571    bool
572    (*surface_get_handle)(struct svga_winsys_screen *sws,
573                          struct svga_winsys_surface *surface,
574                          unsigned stride,
575                          struct winsys_handle *whandle);
576 
577    /**
578     * Whether this surface is sitting in a validate list
579     */
580    bool
581    (*surface_is_flushed)(struct svga_winsys_screen *sws,
582                          struct svga_winsys_surface *surface);
583 
584    /**
585     * Reference a SVGA3D surface object. This allows sharing of a
586     * surface between different objects.
587     */
588    void
589    (*surface_reference)(struct svga_winsys_screen *sws,
590                         struct svga_winsys_surface **pdst,
591                         struct svga_winsys_surface *src);
592 
593    /**
594     * Check if a resource (texture, buffer) of the given size
595     * and format can be created.
596     * \Return TRUE if OK, FALSE if too large.
597     */
598    bool
599    (*surface_can_create)(struct svga_winsys_screen *sws,
600                          SVGA3dSurfaceFormat format,
601                          SVGA3dSize size,
602                          uint32 numLayers,
603                          uint32 numMipLevels,
604                          uint32 numSamples);
605 
606    void
607    (*surface_init)(struct svga_winsys_screen *sws,
608                    struct svga_winsys_surface *surface,
609                    unsigned surf_size, SVGA3dSurfaceAllFlags flags);
610 
611    /**
612     * Buffer management. Buffer attributes are mostly fixed over its lifetime.
613     *
614     * @param usage bitmask of SVGA_BUFFER_USAGE_* flags.
615     *
616     * alignment indicates the client's alignment requirements, eg for
617     * SSE instructions.
618     */
619    struct svga_winsys_buffer *
620    (*buffer_create)( struct svga_winsys_screen *sws,
621                      unsigned alignment,
622                      unsigned usage,
623                      unsigned size );
624 
625    /**
626     * Map the entire data store of a buffer object into the client's address.
627     * usage is a bitmask of PIPE_MAP_*
628     */
629    void *
630    (*buffer_map)( struct svga_winsys_screen *sws,
631                   struct svga_winsys_buffer *buf,
632                   unsigned usage );
633 
634    void
635    (*buffer_unmap)( struct svga_winsys_screen *sws,
636                     struct svga_winsys_buffer *buf );
637 
638    void
639    (*buffer_destroy)( struct svga_winsys_screen *sws,
640                       struct svga_winsys_buffer *buf );
641 
642 
643    /**
644     * Reference a fence object.
645     */
646    void
647    (*fence_reference)( struct svga_winsys_screen *sws,
648                        struct pipe_fence_handle **pdst,
649                        struct pipe_fence_handle *src );
650 
651    /**
652     * Checks whether the fence has been signalled.
653     * \param flags  driver-specific meaning
654     * \return zero on success.
655     */
656    int (*fence_signalled)( struct svga_winsys_screen *sws,
657                            struct pipe_fence_handle *fence,
658                            unsigned flag );
659 
660    /**
661     * Wait for the fence to finish.
662     * \param timeout in nanoseconds (may be OS_TIMEOUT_INFINITE).
663     *                0 to return immediately, if the API suports it.
664     * \param flags  driver-specific meaning
665     * \return zero on success.
666     */
667    int (*fence_finish)( struct svga_winsys_screen *sws,
668                         struct pipe_fence_handle *fence,
669                         uint64_t timeout,
670                         unsigned flag );
671 
672    /**
673     * Get the file descriptor associated with the fence
674     * \param duplicate duplicate the fd before returning it
675     * \return zero on success.
676     */
677    int (*fence_get_fd)( struct svga_winsys_screen *sws,
678                         struct pipe_fence_handle *fence,
679                         bool duplicate );
680 
681    /**
682     * Create a fence using the given file descriptor
683     * \return zero on success.
684     */
685    void (*fence_create_fd)( struct svga_winsys_screen *sws,
686                             struct pipe_fence_handle **fence,
687                             int32_t fd );
688 
689    /**
690     * Accumulates fence FD from other devices into the current context
691     * \param context_fd FD the context will be waiting on
692     * \return zero on success
693     */
694    int (*fence_server_sync)( struct svga_winsys_screen *sws,
695                              int32_t *context_fd,
696                              struct pipe_fence_handle *fence );
697 
698    /**
699     ** BEGIN new functions for guest-backed surfaces.
700     **/
701 
702    /** Are guest-backed objects enabled? */
703    bool have_gb_objects;
704 
705    /** Can we do DMA with guest-backed objects enabled? */
706    bool have_gb_dma;
707 
708    /** Do we support coherent surface memory? */
709    bool have_coherent;
710    /**
711     * Create and define a GB shader.
712     */
713    struct svga_winsys_gb_shader *
714    (*shader_create)(struct svga_winsys_screen *sws,
715                     SVGA3dShaderType shaderType,
716                     const uint32 *bytecode,
717                     uint32 bytecodeLen);
718 
719    /**
720     * Destroy a GB shader. It's safe to call this function even
721     * if the shader is referenced in a context's command stream.
722     */
723    void
724    (*shader_destroy)(struct svga_winsys_screen *sws,
725                      struct svga_winsys_gb_shader *shader);
726 
727    /**
728     * Create and define a GB query.
729     */
730    struct svga_winsys_gb_query *
731    (*query_create)(struct svga_winsys_screen *sws, uint32 len);
732 
733    /**
734     * Destroy a GB query.
735     */
736    void
737    (*query_destroy)(struct svga_winsys_screen *sws,
738                     struct svga_winsys_gb_query *query);
739 
740    /**
741     * Initialize the query state of the query that resides in the slot
742     * specified in offset
743     * \return zero on success.
744     */
745    int
746    (*query_init)(struct svga_winsys_screen *sws,
747                        struct svga_winsys_gb_query *query,
748                        unsigned offset,
749                        SVGA3dQueryState queryState);
750 
751    /**
752     * Inquire for the query state and result of the query that resides
753     * in the slot specified in offset
754     */
755    void
756    (*query_get_result)(struct svga_winsys_screen *sws,
757                        struct svga_winsys_gb_query *query,
758                        unsigned offset,
759                        SVGA3dQueryState *queryState,
760                        void *result, uint32 resultLen);
761 
762    /**
763     * Increment a statistic counter
764     */
765    void
766    (*stats_inc)(struct svga_winsys_screen *, enum svga_stats_count);
767 
768    /**
769     * Push a time frame onto the stack
770     */
771    void
772    (*stats_time_push)(struct svga_winsys_screen *, enum svga_stats_time, struct svga_winsys_stats_timeframe *);
773 
774    /**
775     * Pop a time frame.
776     */
777    void
778    (*stats_time_pop)(struct svga_winsys_screen *);
779 
780    /**
781     * Send a host log message
782     */
783    void
784    (*host_log)(struct svga_winsys_screen *sws, const char *message);
785 
786    /** Have VGPU v10 hardware? */
787    bool have_vgpu10;
788 
789    /** Have SM4_1 hardware? */
790    bool have_sm4_1;
791 
792    /** Have SM5 hardware? */
793    bool have_sm5;
794 
795    /** To rebind resources at the beginning of a new command buffer */
796    bool need_to_rebind_resources;
797 
798    bool have_generate_mipmap_cmd;
799    bool have_set_predication_cmd;
800    bool have_transfer_from_buffer_cmd;
801    bool have_fence_fd;
802    bool have_intra_surface_copy;
803    bool have_constant_buffer_offset_cmd;
804    bool have_index_vertex_buffer_offset_cmd;
805 
806    /* Have rasterizer state v2 command support */
807    bool have_rasterizer_state_v2_cmd;
808 
809    /** Have GL43 capable device */
810    bool have_gl43;
811 
812    /** SVGA device_id version we're running on */
813    uint16_t device_id;
814 };
815 
816 
817 struct svga_winsys_screen *
818 svga_winsys_screen(struct pipe_screen *screen);
819 
820 struct svga_winsys_context *
821 svga_winsys_context(struct pipe_context *context);
822 
823 struct pipe_resource *
824 svga_screen_buffer_wrap_surface(struct pipe_screen *screen,
825                                 enum SVGA3dSurfaceFormat format,
826                                 struct svga_winsys_surface *srf);
827 
828 struct svga_winsys_surface *
829 svga_screen_buffer_get_winsys_surface(struct pipe_resource *buffer);
830 
831 #endif /* SVGA_WINSYS_H_ */
832