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