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