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