summaryrefslogtreecommitdiffstats
path: root/src/gallium/drivers/svga/svga_winsys.h
blob: e74d1ca4d72b679c6519e91b973e55101f85f20b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
/**********************************************************
 * Copyright 2008-2009 VMware, Inc.  All rights reserved.
 *
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use, copy,
 * modify, merge, publish, distribute, sublicense, and/or sell copies
 * of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 *
 **********************************************************/

/**
 * @file
 * VMware SVGA specific winsys interface.
 *
 * @author Jose Fonseca <jfonseca@vmware.com>
 *
 * Documentation taken from the VMware SVGA DDK.
 */

#ifndef SVGA_WINSYS_H_
#define SVGA_WINSYS_H_

#include "svga_types.h"
#include "svga_reg.h"
#include "svga3d_reg.h"

#include "pipe/p_compiler.h"
#include "pipe/p_defines.h"

#include "svga_mksstats.h"

struct svga_winsys_screen;
struct svga_winsys_buffer;
struct pipe_screen;
struct pipe_context;
struct pipe_debug_callback;
struct pipe_fence_handle;
struct pipe_resource;
struct svga_region;
struct winsys_handle;


#define SVGA_BUFFER_USAGE_PINNED  (1 << 0)
#define SVGA_BUFFER_USAGE_WRAPPED (1 << 1)
#define SVGA_BUFFER_USAGE_SHADER  (1 << 2)

/**
 * Relocation flags to help with dirty tracking
 * SVGA_RELOC_WRITE -   The command will cause a GPU write to this
 *                      resource.
 * SVGA_RELOC_READ -    The command will cause a GPU read from this
 *                      resource.
 * SVGA_RELOC_INTERNAL  The command will only transfer data internally
 *                      within the resource, and optionally clear
 *                      dirty bits
 * SVGA_RELOC_DMA -     Only set for resource buffer DMA uploads for winsys
 *                      implementations that want to track the amount
 *                      of such data referenced in the command stream.
 */
#define SVGA_RELOC_WRITE          (1 << 0)
#define SVGA_RELOC_READ           (1 << 1)
#define SVGA_RELOC_INTERNAL       (1 << 2)
#define SVGA_RELOC_DMA            (1 << 3)

#define SVGA_FENCE_FLAG_EXEC      (1 << 0)
#define SVGA_FENCE_FLAG_QUERY     (1 << 1)

#define SVGA_SURFACE_USAGE_SHARED  (1 << 0)
#define SVGA_SURFACE_USAGE_SCANOUT (1 << 1)

#define SVGA_QUERY_FLAG_SET        (1 << 0)
#define SVGA_QUERY_FLAG_REF        (1 << 1)

#define SVGA_HINT_FLAG_CAN_PRE_FLUSH   (1 << 0)  /* Can preemptively flush */
#define SVGA_HINT_FLAG_EXPORT_FENCE_FD (1 << 1)  /* Export a Fence FD */

/**
 * SVGA mks statistics info
 */
struct svga_winsys_stats_timeframe {
   void *counterTime;
   uint64 startTime;
   uint64 adjustedStartTime;
   struct svga_winsys_stats_timeframe *enclosing;
};

enum svga_stats_count {
   SVGA_STATS_COUNT_BLENDSTATE,
   SVGA_STATS_COUNT_BLITBLITTERCOPY,
   SVGA_STATS_COUNT_DEPTHSTENCILSTATE,
   SVGA_STATS_COUNT_RASTERIZERSTATE,
   SVGA_STATS_COUNT_SAMPLER,
   SVGA_STATS_COUNT_SAMPLERVIEW,
   SVGA_STATS_COUNT_SURFACEWRITEFLUSH,
   SVGA_STATS_COUNT_TEXREADBACK,
   SVGA_STATS_COUNT_VERTEXELEMENT,
   SVGA_STATS_COUNT_MAX
};

enum svga_stats_time {
   SVGA_STATS_TIME_BLIT,
   SVGA_STATS_TIME_BLITBLITTER,
   SVGA_STATS_TIME_BLITFALLBACK,
   SVGA_STATS_TIME_BUFFERSFLUSH,
   SVGA_STATS_TIME_BUFFERTRANSFERMAP,
   SVGA_STATS_TIME_BUFFERTRANSFERUNMAP,
   SVGA_STATS_TIME_CONTEXTFINISH,
   SVGA_STATS_TIME_CONTEXTFLUSH,
   SVGA_STATS_TIME_COPYREGION,
   SVGA_STATS_TIME_COPYREGIONFALLBACK,
   SVGA_STATS_TIME_CREATEBACKEDSURFACEVIEW,
   SVGA_STATS_TIME_CREATEBUFFER,
   SVGA_STATS_TIME_CREATECONTEXT,
   SVGA_STATS_TIME_CREATEFS,
   SVGA_STATS_TIME_CREATEGS,
   SVGA_STATS_TIME_CREATESURFACE,
   SVGA_STATS_TIME_CREATESURFACEVIEW,
   SVGA_STATS_TIME_CREATETEXTURE,
   SVGA_STATS_TIME_CREATEVS,
   SVGA_STATS_TIME_DEFINESHADER,
   SVGA_STATS_TIME_DESTROYSURFACE,
   SVGA_STATS_TIME_DRAWVBO,
   SVGA_STATS_TIME_DRAWARRAYS,
   SVGA_STATS_TIME_DRAWELEMENTS,
   SVGA_STATS_TIME_EMITFS,
   SVGA_STATS_TIME_EMITGS,
   SVGA_STATS_TIME_EMITVS,
   SVGA_STATS_TIME_EMULATESURFACEVIEW,
   SVGA_STATS_TIME_FENCEFINISH,
   SVGA_STATS_TIME_GENERATEINDICES,
   SVGA_STATS_TIME_HWTNLDRAWARRAYS,
   SVGA_STATS_TIME_HWTNLDRAWELEMENTS,
   SVGA_STATS_TIME_HWTNLFLUSH,
   SVGA_STATS_TIME_HWTNLPRIM,
   SVGA_STATS_TIME_PROPAGATESURFACE,
   SVGA_STATS_TIME_SETSAMPLERVIEWS,
   SVGA_STATS_TIME_SURFACEFLUSH,
   SVGA_STATS_TIME_SWTNLDRAWVBO,
   SVGA_STATS_TIME_SWTNLUPDATEDRAW,
   SVGA_STATS_TIME_SWTNLUPDATEVDECL,
   SVGA_STATS_TIME_TEXTRANSFERMAP,
   SVGA_STATS_TIME_TEXTRANSFERUNMAP,
   SVGA_STATS_TIME_TGSIVGPU10TRANSLATE,
   SVGA_STATS_TIME_TGSIVGPU9TRANSLATE,
   SVGA_STATS_TIME_UPDATESTATE,
   SVGA_STATS_TIME_VALIDATESURFACEVIEW,
   SVGA_STATS_TIME_VBUFDRAWARRAYS,
   SVGA_STATS_TIME_VBUFDRAWELEMENTS,
   SVGA_STATS_TIME_VBUFRENDERALLOCVERT,
   SVGA_STATS_TIME_VBUFRENDERMAPVERT,
   SVGA_STATS_TIME_VBUFRENDERUNMAPVERT,
   SVGA_STATS_TIME_VBUFSUBMITSTATE,
   SVGA_STATS_TIME_MAX
};

#define SVGA_STATS_PREFIX "GuestGL_"

#define SVGA_STATS_COUNT_NAMES                \
   SVGA_STATS_PREFIX "BlendState",            \
   SVGA_STATS_PREFIX "BlitBlitterCopy",       \
   SVGA_STATS_PREFIX "DepthStencilState",     \
   SVGA_STATS_PREFIX "RasterizerState",       \
   SVGA_STATS_PREFIX "Sampler",               \
   SVGA_STATS_PREFIX "SamplerView",           \
   SVGA_STATS_PREFIX "SurfaceWriteFlush",     \
   SVGA_STATS_PREFIX "TextureReadback",       \
   SVGA_STATS_PREFIX "VertexElement"          \

#define SVGA_STATS_TIME_NAMES                       \
   SVGA_STATS_PREFIX "Blit",                        \
   SVGA_STATS_PREFIX "BlitBlitter",                 \
   SVGA_STATS_PREFIX "BlitFallback",                \
   SVGA_STATS_PREFIX "BuffersFlush",                \
   SVGA_STATS_PREFIX "BufferTransferMap",           \
   SVGA_STATS_PREFIX "BufferTransferUnmap",         \
   SVGA_STATS_PREFIX "ContextFinish",               \
   SVGA_STATS_PREFIX "ContextFlush",                \
   SVGA_STATS_PREFIX "CopyRegion",                  \
   SVGA_STATS_PREFIX "CopyRegionFallback",          \
   SVGA_STATS_PREFIX "CreateBackedSurfaceView",     \
   SVGA_STATS_PREFIX "CreateBuffer",                \
   SVGA_STATS_PREFIX "CreateContext",               \
   SVGA_STATS_PREFIX "CreateFS",                    \
   SVGA_STATS_PREFIX "CreateGS",                    \
   SVGA_STATS_PREFIX "CreateSurface",               \
   SVGA_STATS_PREFIX "CreateSurfaceView",           \
   SVGA_STATS_PREFIX "CreateTexture",               \
   SVGA_STATS_PREFIX "CreateVS",                    \
   SVGA_STATS_PREFIX "DefineShader",                \
   SVGA_STATS_PREFIX "DestroySurface",              \
   SVGA_STATS_PREFIX "DrawVBO",                     \
   SVGA_STATS_PREFIX "DrawArrays",                  \
   SVGA_STATS_PREFIX "DrawElements",                \
   SVGA_STATS_PREFIX "EmitFS",                      \
   SVGA_STATS_PREFIX "EmitGS",                      \
   SVGA_STATS_PREFIX "EmitVS",                      \
   SVGA_STATS_PREFIX "EmulateSurfaceView",          \
   SVGA_STATS_PREFIX "FenceFinish",                 \
   SVGA_STATS_PREFIX "GenerateIndices",             \
   SVGA_STATS_PREFIX "HWtnlDrawArrays",             \
   SVGA_STATS_PREFIX "HWtnlDrawElements",           \
   SVGA_STATS_PREFIX "HWtnlFlush",                  \
   SVGA_STATS_PREFIX "HWtnlPrim",                   \
   SVGA_STATS_PREFIX "PropagateSurface",            \
   SVGA_STATS_PREFIX "SetSamplerViews",             \
   SVGA_STATS_PREFIX "SurfaceFlush",                \
   SVGA_STATS_PREFIX "SwtnlDrawVBO",                \
   SVGA_STATS_PREFIX "SwtnlUpdateDraw",             \
   SVGA_STATS_PREFIX "SwtnlUpdateVDecl",            \
   SVGA_STATS_PREFIX "TextureTransferMap",          \
   SVGA_STATS_PREFIX "TextureTransferUnmap",        \
   SVGA_STATS_PREFIX "TGSIVGPU10Translate",         \
   SVGA_STATS_PREFIX "TGSIVGPU9Translate",          \
   SVGA_STATS_PREFIX "UpdateState",                 \
   SVGA_STATS_PREFIX "ValidateSurfaceView",         \
   SVGA_STATS_PREFIX "VbufDrawArrays",              \
   SVGA_STATS_PREFIX "VbufDrawElements",            \
   SVGA_STATS_PREFIX "VbufRenderAllocVertices",     \
   SVGA_STATS_PREFIX "VbufRenderMapVertices",       \
   SVGA_STATS_PREFIX "VbufRenderUnmapVertices",     \
   SVGA_STATS_PREFIX "VbufSubmitState"


/** Opaque surface handle */
struct svga_winsys_surface;

/** Opaque guest-backed objects */
struct svga_winsys_gb_shader;
struct svga_winsys_gb_query;


/**
 * SVGA per-context winsys interface.
 */
struct svga_winsys_context
{
   void
   (*destroy)(struct svga_winsys_context *swc);

   void *
   (*reserve)(struct svga_winsys_context *swc,
              uint32_t nr_bytes, uint32_t nr_relocs );

   /**
    * Returns current size of command buffer, in bytes.
    */
   unsigned
   (*get_command_buffer_size)(struct svga_winsys_context *swc);

   /**
    * Emit a relocation for a host surface.
    *
    * @param flags bitmask of SVGA_RELOC_* flags
    *
    * NOTE: Order of this call does matter. It should be the same order
    * as relocations appear in the command buffer.
    */
   void
   (*surface_relocation)(struct svga_winsys_context *swc,
                         uint32 *sid,
                         uint32 *mobid,
                         struct svga_winsys_surface *surface,
                         unsigned flags);

   /**
    * Emit a relocation for a guest memory region.
    *
    * @param flags bitmask of SVGA_RELOC_* flags
    *
    * NOTE: Order of this call does matter. It should be the same order
    * as relocations appear in the command buffer.
    */
   void
   (*region_relocation)(struct svga_winsys_context *swc,
                        struct SVGAGuestPtr *ptr,
                        struct svga_winsys_buffer *buffer,
                        uint32 offset,
                        unsigned flags);

   /**
    * Emit a relocation for a guest-backed shader object.
    *
    * NOTE: Order of this call does matter. It should be the same order
    * as relocations appear in the command buffer.
    */
   void
   (*shader_relocation)(struct svga_winsys_context *swc,
                        uint32 *shid,
                        uint32 *mobid,
                        uint32 *offset,
                        struct svga_winsys_gb_shader *shader,
                        unsigned flags);

   /**
    * Emit a relocation for a guest-backed context.
    *
    * NOTE: Order of this call does matter. It should be the same order
    * as relocations appear in the command buffer.
    */
   void
   (*context_relocation)(struct svga_winsys_context *swc, uint32 *cid);

   /**
    * Emit a relocation for a guest Memory OBject.
    *
    * @param flags bitmask of SVGA_RELOC_* flags
    * @param offset_into_mob Buffer starts at this offset into the MOB.
    *
    * Note that not all commands accept an offset into the MOB and
    * those commands can't use suballocated buffer pools. To trap
    * errors from improper buffer pool usage, set the offset_into_mob
    * pointer to NULL.
    */
   void
   (*mob_relocation)(struct svga_winsys_context *swc,
                     SVGAMobId *id,
                     uint32 *offset_into_mob,
                     struct svga_winsys_buffer *buffer,
                     uint32 offset,
                     unsigned flags);

   /**
    * Emit a relocation for a guest-backed query object.
    *
    * NOTE: Order of this call does matter. It should be the same order
    * as relocations appear in the command buffer.
    */
   void
   (*query_relocation)(struct svga_winsys_context *swc,
                       SVGAMobId *id,
                       struct svga_winsys_gb_query *query);

   /**
    * Bind queries to context.
    * \param flags  exactly one of SVGA_QUERY_FLAG_SET/REF
    */
   enum pipe_error
   (*query_bind)(struct svga_winsys_context *sws,
                 struct svga_winsys_gb_query *query,
                 unsigned flags);

   void
   (*commit)(struct svga_winsys_context *swc);

   enum pipe_error
   (*flush)(struct svga_winsys_context *swc,
            struct pipe_fence_handle **pfence);

   /**
    * Context ID used to fill in the commands
    *
    * Context IDs are arbitrary small non-negative integers,
    * global to the entire SVGA device.
    */
   uint32 cid;

   /**
    * Flags to hint the current context state
    */
   uint32 hints;

   /**
    * File descriptor for imported fence
    */
   int32 imported_fence_fd;

   /**
    ** BEGIN new functions for guest-backed surfaces.
    **/

   boolean have_gb_objects;

   /**
    * Map a guest-backed surface.
    * \param flags  bitmaks of PIPE_TRANSFER_x flags
    *
    * The surface_map() member is allowed to fail due to a
    * shortage of command buffer space, if the
    * PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE bit is set in flags.
    * In that case, the caller must flush the current command
    * buffer and reissue the map.
    */
   void *
   (*surface_map)(struct svga_winsys_context *swc,
                  struct svga_winsys_surface *surface,
                  unsigned flags, boolean *retry);

   /**
    * Unmap a guest-backed surface.
    * \param rebind  returns a flag indicating whether the caller should
    *                issue a SVGA3D_BindGBSurface() call.
    */
   void
   (*surface_unmap)(struct svga_winsys_context *swc,
                    struct svga_winsys_surface *surface,
                    boolean *rebind);

   /**
    * Invalidate the content of this surface
    */
   enum pipe_error
   (*surface_invalidate)(struct svga_winsys_context *swc,
                         struct svga_winsys_surface *surface);

   /**
    * Create and define a DX GB shader that resides in the device COTable.
    * Caller of this function will issue the DXDefineShader command.
    */
   struct svga_winsys_gb_shader *
   (*shader_create)(struct svga_winsys_context *swc,
                    uint32 shaderId,
                    SVGA3dShaderType shaderType,
                    const uint32 *bytecode,
                    uint32 bytecodeLen);

   /**
    * Destroy a DX GB shader.
    * This function will issue the DXDestroyShader command.
    */
   void
   (*shader_destroy)(struct svga_winsys_context *swc,
                     struct svga_winsys_gb_shader *shader);

   /**
    * Rebind a DX GB resource to a context.
    * This is called to reference a DX GB resource in the command stream in
    * order to page in the associated resource in case the memory has been
    * paged out, and to fence it if necessary after command submission.
    */
   enum pipe_error
   (*resource_rebind)(struct svga_winsys_context *swc,
                      struct svga_winsys_surface *surface,
                      struct svga_winsys_gb_shader *shader,
                      unsigned flags);

   /** To report perf/conformance/etc issues to the state tracker */
   struct pipe_debug_callback *debug_callback;

   /** The more recent command issued to command buffer */
   SVGAFifo3dCmdId last_command;
};


/**
 * SVGA per-screen winsys interface.
 */
struct svga_winsys_screen
{
   void
   (*destroy)(struct svga_winsys_screen *sws);

   SVGA3dHardwareVersion
   (*get_hw_version)(struct svga_winsys_screen *sws);

   boolean
   (*get_cap)(struct svga_winsys_screen *sws,
              SVGA3dDevCapIndex index,
              SVGA3dDevCapResult *result);

   /**
    * Create a new context.
    *
    * Context objects encapsulate all render state, and shader
    * objects are per-context.
    *
    * Surfaces are not per-context. The same surface can be shared
    * between multiple contexts, and surface operations can occur
    * without a context.
    */
   struct svga_winsys_context *
   (*context_create)(struct svga_winsys_screen *sws);

   /**
    * This creates a "surface" object in the SVGA3D device.
    *
    * \param sws Pointer to an svga_winsys_context
    * \param flags Device surface create flags
    * \param format Format Device surface format
    * \param usage Winsys usage: bitmask of SVGA_SURFACE_USAGE_x flags
    * \param size Surface size given in device format
    * \param numLayers Number of layers of the surface (or cube faces)
    * \param numMipLevels Number of mipmap levels for each face
    *
    * Returns the surface ID (sid). Surfaces are generic
    * containers for host VRAM objects like textures, vertex
    * buffers, and depth/stencil buffers.
    *
    * Surfaces are hierarchial:
    *
    * - Surface may have multiple faces (for cube maps)
    *
    * - Each face has a list of mipmap levels
    *
    * - Each mipmap image may have multiple volume
    *   slices for 3D image, or multiple 2D slices for texture array.
    *
    * - Each slice is a 2D array of 'blocks'
    *
    * - Each block may be one or more pixels.
    *   (Usually 1, more for DXT or YUV formats.)
    *
    * Surfaces are generic host VRAM objects. The SVGA3D device
    * may optimize surfaces according to the format they were
    * created with, but this format does not limit the ways in
    * which the surface may be used. For example, a depth surface
    * can be used as a texture, or a floating point image may
    * be used as a vertex buffer. Some surface usages may be
    * lower performance, due to software emulation, but any
    * usage should work with any surface.
    */
   struct svga_winsys_surface *
   (*surface_create)(struct svga_winsys_screen *sws,
                     SVGA3dSurfaceFlags flags,
                     SVGA3dSurfaceFormat format,
                     unsigned usage,
                     SVGA3dSize size,
                     uint32 numLayers,
                     uint32 numMipLevels,
                     unsigned sampleCount);

   /**
    * Creates a surface from a winsys handle.
    * Used to implement pipe_screen::resource_from_handle.
    */
   struct svga_winsys_surface *
   (*surface_from_handle)(struct svga_winsys_screen *sws,
                          struct winsys_handle *whandle,
                          SVGA3dSurfaceFormat *format);

   /**
    * Get a winsys_handle from a surface.
    * Used to implement pipe_screen::resource_get_handle.
    */
   boolean
   (*surface_get_handle)(struct svga_winsys_screen *sws,
                         struct svga_winsys_surface *surface,
                         unsigned stride,
                         struct winsys_handle *whandle);

   /**
    * Whether this surface is sitting in a validate list
    */
   boolean
   (*surface_is_flushed)(struct svga_winsys_screen *sws,
                         struct svga_winsys_surface *surface);

   /**
    * Reference a SVGA3D surface object. This allows sharing of a
    * surface between different objects.
    */
   void
   (*surface_reference)(struct svga_winsys_screen *sws,
                        struct svga_winsys_surface **pdst,
                        struct svga_winsys_surface *src);

   /**
    * Check if a resource (texture, buffer) of the given size
    * and format can be created.
    * \Return TRUE if OK, FALSE if too large.
    */
   boolean
   (*surface_can_create)(struct svga_winsys_screen *sws,
                         SVGA3dSurfaceFormat format,
                         SVGA3dSize size,
                         uint32 numLayers,
                         uint32 numMipLevels);

   /**
    * Buffer management. Buffer attributes are mostly fixed over its lifetime.
    *
    * @param usage bitmask of SVGA_BUFFER_USAGE_* flags.
    *
    * alignment indicates the client's alignment requirements, eg for
    * SSE instructions.
    */
   struct svga_winsys_buffer *
   (*buffer_create)( struct svga_winsys_screen *sws,
                     unsigned alignment,
                     unsigned usage,
                     unsigned size );

   /**
    * Map the entire data store of a buffer object into the client's address.
    * usage is a bitmask of PIPE_TRANSFER_*
    */
   void *
   (*buffer_map)( struct svga_winsys_screen *sws,
                  struct svga_winsys_buffer *buf,
                  unsigned usage );

   void
   (*buffer_unmap)( struct svga_winsys_screen *sws,
                    struct svga_winsys_buffer *buf );

   void
   (*buffer_destroy)( struct svga_winsys_screen *sws,
                      struct svga_winsys_buffer *buf );


   /**
    * Reference a fence object.
    */
   void
   (*fence_reference)( struct svga_winsys_screen *sws,
                       struct pipe_fence_handle **pdst,
                       struct pipe_fence_handle *src );

   /**
    * Checks whether the fence has been signalled.
    * \param flags  driver-specific meaning
    * \return zero on success.
    */
   int (*fence_signalled)( struct svga_winsys_screen *sws,
                           struct pipe_fence_handle *fence,
                           unsigned flag );

   /**
    * Wait for the fence to finish.
    * \param timeout in nanoseconds (may be PIPE_TIMEOUT_INFINITE).
    *                0 to return immediately, if the API suports it.
    * \param flags  driver-specific meaning
    * \return zero on success.
    */
   int (*fence_finish)( struct svga_winsys_screen *sws,
                        struct pipe_fence_handle *fence,
                        uint64_t timeout,
                        unsigned flag );

   /**
    * Get the file descriptor associated with the fence
    * \param duplicate duplicate the fd before returning it
    * \return zero on success.
    */
   int (*fence_get_fd)( struct svga_winsys_screen *sws,
                        struct pipe_fence_handle *fence,
                        boolean duplicate );

   /**
    * Create a fence using the given file descriptor
    * \return zero on success.
    */
   void (*fence_create_fd)( struct svga_winsys_screen *sws,
                            struct pipe_fence_handle **fence,
                            int32_t fd );

   /**
    * Accumulates fence FD from other devices into the current context
    * \param context_fd FD the context will be waiting on
    * \return zero on success
    */
   int (*fence_server_sync)( struct svga_winsys_screen *sws,
                             int32_t *context_fd,
                             struct pipe_fence_handle *fence );

   /**
    ** BEGIN new functions for guest-backed surfaces.
    **/

   /** Are guest-backed objects enabled? */
   bool have_gb_objects;

   /** Can we do DMA with guest-backed objects enabled? */
   bool have_gb_dma;

   /**
    * Create and define a GB shader.
    */
   struct svga_winsys_gb_shader *
   (*shader_create)(struct svga_winsys_screen *sws,
                    SVGA3dShaderType shaderType,
                    const uint32 *bytecode,
                    uint32 bytecodeLen);

   /**
    * Destroy a GB shader. It's safe to call this function even
    * if the shader is referenced in a context's command stream.
    */
   void
   (*shader_destroy)(struct svga_winsys_screen *sws,
                     struct svga_winsys_gb_shader *shader);

   /**
    * Create and define a GB query.
    */
   struct svga_winsys_gb_query *
   (*query_create)(struct svga_winsys_screen *sws, uint32 len);

   /**
    * Destroy a GB query.
    */
   void
   (*query_destroy)(struct svga_winsys_screen *sws,
                    struct svga_winsys_gb_query *query);

   /**
    * Initialize the query state of the query that resides in the slot
    * specified in offset
    * \return zero on success.
    */
   int
   (*query_init)(struct svga_winsys_screen *sws,
                       struct svga_winsys_gb_query *query,
                       unsigned offset,
                       SVGA3dQueryState queryState);

   /**
    * Inquire for the query state and result of the query that resides
    * in the slot specified in offset
    */
   void
   (*query_get_result)(struct svga_winsys_screen *sws,
                       struct svga_winsys_gb_query *query,
                       unsigned offset,
                       SVGA3dQueryState *queryState,
                       void *result, uint32 resultLen);

   /**
    * Increment a statistic counter
    */
   void
   (*stats_inc)(enum svga_stats_count);

   /**
    * Push a time frame onto the stack
    */
   void
   (*stats_time_push)(enum svga_stats_time, struct svga_winsys_stats_timeframe *);

   /**
    * Pop a time frame.
    */
   void
   (*stats_time_pop)();


   /** Have VGPU v10 hardware? */
   boolean have_vgpu10;

   /** To rebind resources at the beginnning of a new command buffer */
   boolean need_to_rebind_resources;

   boolean have_generate_mipmap_cmd;
   boolean have_set_predication_cmd;
   boolean have_transfer_from_buffer_cmd;
   boolean have_fence_fd;
};


struct svga_winsys_screen *
svga_winsys_screen(struct pipe_screen *screen);

struct svga_winsys_context *
svga_winsys_context(struct pipe_context *context);

struct pipe_resource *
svga_screen_buffer_wrap_surface(struct pipe_screen *screen,
                                enum SVGA3dSurfaceFormat format,
                                struct svga_winsys_surface *srf);

struct svga_winsys_surface *
svga_screen_buffer_get_winsys_surface(struct pipe_resource *buffer);

#endif /* SVGA_WINSYS_H_ */