1848b8605Smrg/**********************************************************
2848b8605Smrg * Copyright 2008-2009 VMware, Inc.  All rights reserved.
3848b8605Smrg *
4848b8605Smrg * Permission is hereby granted, free of charge, to any person
5848b8605Smrg * obtaining a copy of this software and associated documentation
6848b8605Smrg * files (the "Software"), to deal in the Software without
7848b8605Smrg * restriction, including without limitation the rights to use, copy,
8848b8605Smrg * modify, merge, publish, distribute, sublicense, and/or sell copies
9848b8605Smrg * of the Software, and to permit persons to whom the Software is
10848b8605Smrg * furnished to do so, subject to the following conditions:
11848b8605Smrg *
12848b8605Smrg * The above copyright notice and this permission notice shall be
13848b8605Smrg * included in all copies or substantial portions of the Software.
14848b8605Smrg *
15848b8605Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16848b8605Smrg * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17848b8605Smrg * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18848b8605Smrg * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19848b8605Smrg * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20848b8605Smrg * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21848b8605Smrg * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22848b8605Smrg * SOFTWARE.
23848b8605Smrg *
24848b8605Smrg **********************************************************/
25848b8605Smrg
26848b8605Smrg/**
27848b8605Smrg * @file
28848b8605Smrg * VMware SVGA specific winsys interface.
29b8e80941Smrg *
30848b8605Smrg * @author Jose Fonseca <jfonseca@vmware.com>
31b8e80941Smrg *
32848b8605Smrg * Documentation taken from the VMware SVGA DDK.
33848b8605Smrg */
34848b8605Smrg
35848b8605Smrg#ifndef SVGA_WINSYS_H_
36848b8605Smrg#define SVGA_WINSYS_H_
37848b8605Smrg
38848b8605Smrg#include "svga_types.h"
39b8e80941Smrg#include "svga3d_types.h"
40848b8605Smrg#include "svga_reg.h"
41848b8605Smrg#include "svga3d_reg.h"
42848b8605Smrg
43848b8605Smrg#include "pipe/p_compiler.h"
44848b8605Smrg#include "pipe/p_defines.h"
45848b8605Smrg
46b8e80941Smrg#include "svga_mksstats.h"
47848b8605Smrg
48848b8605Smrgstruct svga_winsys_screen;
49848b8605Smrgstruct svga_winsys_buffer;
50848b8605Smrgstruct pipe_screen;
51848b8605Smrgstruct pipe_context;
52b8e80941Smrgstruct pipe_debug_callback;
53848b8605Smrgstruct pipe_fence_handle;
54848b8605Smrgstruct pipe_resource;
55848b8605Smrgstruct svga_region;
56848b8605Smrgstruct winsys_handle;
57848b8605Smrg
58848b8605Smrg
59848b8605Smrg#define SVGA_BUFFER_USAGE_PINNED  (1 << 0)
60848b8605Smrg#define SVGA_BUFFER_USAGE_WRAPPED (1 << 1)
61848b8605Smrg#define SVGA_BUFFER_USAGE_SHADER  (1 << 2)
62848b8605Smrg
63848b8605Smrg/**
64848b8605Smrg * Relocation flags to help with dirty tracking
65848b8605Smrg * SVGA_RELOC_WRITE -   The command will cause a GPU write to this
66848b8605Smrg *                      resource.
67848b8605Smrg * SVGA_RELOC_READ -    The command will cause a GPU read from this
68848b8605Smrg *                      resource.
69848b8605Smrg * SVGA_RELOC_INTERNAL  The command will only transfer data internally
70848b8605Smrg *                      within the resource, and optionally clear
71848b8605Smrg *                      dirty bits
72848b8605Smrg * SVGA_RELOC_DMA -     Only set for resource buffer DMA uploads for winsys
73848b8605Smrg *                      implementations that want to track the amount
74848b8605Smrg *                      of such data referenced in the command stream.
75848b8605Smrg */
76848b8605Smrg#define SVGA_RELOC_WRITE          (1 << 0)
77848b8605Smrg#define SVGA_RELOC_READ           (1 << 1)
78848b8605Smrg#define SVGA_RELOC_INTERNAL       (1 << 2)
79848b8605Smrg#define SVGA_RELOC_DMA            (1 << 3)
80848b8605Smrg
81848b8605Smrg#define SVGA_FENCE_FLAG_EXEC      (1 << 0)
82848b8605Smrg#define SVGA_FENCE_FLAG_QUERY     (1 << 1)
83848b8605Smrg
84b8e80941Smrg#define SVGA_SURFACE_USAGE_SHARED  (1 << 0)
85b8e80941Smrg#define SVGA_SURFACE_USAGE_SCANOUT (1 << 1)
86b8e80941Smrg
87b8e80941Smrg#define SVGA_QUERY_FLAG_SET        (1 << 0)
88b8e80941Smrg#define SVGA_QUERY_FLAG_REF        (1 << 1)
89b8e80941Smrg
90b8e80941Smrg#define SVGA_HINT_FLAG_CAN_PRE_FLUSH   (1 << 0)  /* Can preemptively flush */
91b8e80941Smrg#define SVGA_HINT_FLAG_EXPORT_FENCE_FD (1 << 1)  /* Export a Fence FD */
92b8e80941Smrg
93b8e80941Smrg/**
94b8e80941Smrg * SVGA mks statistics info
95b8e80941Smrg */
96b8e80941Smrgstruct svga_winsys_stats_timeframe {
97b8e80941Smrg   void *counterTime;
98b8e80941Smrg   uint64 startTime;
99b8e80941Smrg   uint64 adjustedStartTime;
100b8e80941Smrg   struct svga_winsys_stats_timeframe *enclosing;
101b8e80941Smrg};
102b8e80941Smrg
103b8e80941Smrgenum svga_stats_count {
104b8e80941Smrg   SVGA_STATS_COUNT_BLENDSTATE,
105b8e80941Smrg   SVGA_STATS_COUNT_BLITBLITTERCOPY,
106b8e80941Smrg   SVGA_STATS_COUNT_DEPTHSTENCILSTATE,
107b8e80941Smrg   SVGA_STATS_COUNT_RASTERIZERSTATE,
108b8e80941Smrg   SVGA_STATS_COUNT_SAMPLER,
109b8e80941Smrg   SVGA_STATS_COUNT_SAMPLERVIEW,
110b8e80941Smrg   SVGA_STATS_COUNT_SURFACEWRITEFLUSH,
111b8e80941Smrg   SVGA_STATS_COUNT_TEXREADBACK,
112b8e80941Smrg   SVGA_STATS_COUNT_VERTEXELEMENT,
113b8e80941Smrg   SVGA_STATS_COUNT_MAX
114b8e80941Smrg};
115b8e80941Smrg
116b8e80941Smrgenum svga_stats_time {
117b8e80941Smrg   SVGA_STATS_TIME_BLIT,
118b8e80941Smrg   SVGA_STATS_TIME_BLITBLITTER,
119b8e80941Smrg   SVGA_STATS_TIME_BLITFALLBACK,
120b8e80941Smrg   SVGA_STATS_TIME_BUFFERSFLUSH,
121b8e80941Smrg   SVGA_STATS_TIME_BUFFERTRANSFERMAP,
122b8e80941Smrg   SVGA_STATS_TIME_BUFFERTRANSFERUNMAP,
123b8e80941Smrg   SVGA_STATS_TIME_CONTEXTFINISH,
124b8e80941Smrg   SVGA_STATS_TIME_CONTEXTFLUSH,
125b8e80941Smrg   SVGA_STATS_TIME_COPYREGION,
126b8e80941Smrg   SVGA_STATS_TIME_COPYREGIONFALLBACK,
127b8e80941Smrg   SVGA_STATS_TIME_CREATEBACKEDSURFACEVIEW,
128b8e80941Smrg   SVGA_STATS_TIME_CREATEBUFFER,
129b8e80941Smrg   SVGA_STATS_TIME_CREATECONTEXT,
130b8e80941Smrg   SVGA_STATS_TIME_CREATEFS,
131b8e80941Smrg   SVGA_STATS_TIME_CREATEGS,
132b8e80941Smrg   SVGA_STATS_TIME_CREATESURFACE,
133b8e80941Smrg   SVGA_STATS_TIME_CREATESURFACEVIEW,
134b8e80941Smrg   SVGA_STATS_TIME_CREATETEXTURE,
135b8e80941Smrg   SVGA_STATS_TIME_CREATEVS,
136b8e80941Smrg   SVGA_STATS_TIME_DEFINESHADER,
137b8e80941Smrg   SVGA_STATS_TIME_DESTROYSURFACE,
138b8e80941Smrg   SVGA_STATS_TIME_DRAWVBO,
139b8e80941Smrg   SVGA_STATS_TIME_DRAWARRAYS,
140b8e80941Smrg   SVGA_STATS_TIME_DRAWELEMENTS,
141b8e80941Smrg   SVGA_STATS_TIME_EMITFS,
142b8e80941Smrg   SVGA_STATS_TIME_EMITGS,
143b8e80941Smrg   SVGA_STATS_TIME_EMITVS,
144b8e80941Smrg   SVGA_STATS_TIME_EMULATESURFACEVIEW,
145b8e80941Smrg   SVGA_STATS_TIME_FENCEFINISH,
146b8e80941Smrg   SVGA_STATS_TIME_GENERATEINDICES,
147b8e80941Smrg   SVGA_STATS_TIME_HWTNLDRAWARRAYS,
148b8e80941Smrg   SVGA_STATS_TIME_HWTNLDRAWELEMENTS,
149b8e80941Smrg   SVGA_STATS_TIME_HWTNLFLUSH,
150b8e80941Smrg   SVGA_STATS_TIME_HWTNLPRIM,
151b8e80941Smrg   SVGA_STATS_TIME_PROPAGATESURFACE,
152b8e80941Smrg   SVGA_STATS_TIME_SETSAMPLERVIEWS,
153b8e80941Smrg   SVGA_STATS_TIME_SURFACEFLUSH,
154b8e80941Smrg   SVGA_STATS_TIME_SWTNLDRAWVBO,
155b8e80941Smrg   SVGA_STATS_TIME_SWTNLUPDATEDRAW,
156b8e80941Smrg   SVGA_STATS_TIME_SWTNLUPDATEVDECL,
157b8e80941Smrg   SVGA_STATS_TIME_TEXTRANSFERMAP,
158b8e80941Smrg   SVGA_STATS_TIME_TEXTRANSFERUNMAP,
159b8e80941Smrg   SVGA_STATS_TIME_TGSIVGPU10TRANSLATE,
160b8e80941Smrg   SVGA_STATS_TIME_TGSIVGPU9TRANSLATE,
161b8e80941Smrg   SVGA_STATS_TIME_UPDATESTATE,
162b8e80941Smrg   SVGA_STATS_TIME_VALIDATESURFACEVIEW,
163b8e80941Smrg   SVGA_STATS_TIME_VBUFDRAWARRAYS,
164b8e80941Smrg   SVGA_STATS_TIME_VBUFDRAWELEMENTS,
165b8e80941Smrg   SVGA_STATS_TIME_VBUFRENDERALLOCVERT,
166b8e80941Smrg   SVGA_STATS_TIME_VBUFRENDERMAPVERT,
167b8e80941Smrg   SVGA_STATS_TIME_VBUFRENDERUNMAPVERT,
168b8e80941Smrg   SVGA_STATS_TIME_VBUFSUBMITSTATE,
169b8e80941Smrg   SVGA_STATS_TIME_MAX
170b8e80941Smrg};
171b8e80941Smrg
172b8e80941Smrg#define SVGA_STATS_PREFIX "GuestGL_"
173b8e80941Smrg
174b8e80941Smrg#define SVGA_STATS_COUNT_NAMES                \
175b8e80941Smrg   SVGA_STATS_PREFIX "BlendState",            \
176b8e80941Smrg   SVGA_STATS_PREFIX "BlitBlitterCopy",       \
177b8e80941Smrg   SVGA_STATS_PREFIX "DepthStencilState",     \
178b8e80941Smrg   SVGA_STATS_PREFIX "RasterizerState",       \
179b8e80941Smrg   SVGA_STATS_PREFIX "Sampler",               \
180b8e80941Smrg   SVGA_STATS_PREFIX "SamplerView",           \
181b8e80941Smrg   SVGA_STATS_PREFIX "SurfaceWriteFlush",     \
182b8e80941Smrg   SVGA_STATS_PREFIX "TextureReadback",       \
183b8e80941Smrg   SVGA_STATS_PREFIX "VertexElement"          \
184b8e80941Smrg
185b8e80941Smrg#define SVGA_STATS_TIME_NAMES                       \
186b8e80941Smrg   SVGA_STATS_PREFIX "Blit",                        \
187b8e80941Smrg   SVGA_STATS_PREFIX "BlitBlitter",                 \
188b8e80941Smrg   SVGA_STATS_PREFIX "BlitFallback",                \
189b8e80941Smrg   SVGA_STATS_PREFIX "BuffersFlush",                \
190b8e80941Smrg   SVGA_STATS_PREFIX "BufferTransferMap",           \
191b8e80941Smrg   SVGA_STATS_PREFIX "BufferTransferUnmap",         \
192b8e80941Smrg   SVGA_STATS_PREFIX "ContextFinish",               \
193b8e80941Smrg   SVGA_STATS_PREFIX "ContextFlush",                \
194b8e80941Smrg   SVGA_STATS_PREFIX "CopyRegion",                  \
195b8e80941Smrg   SVGA_STATS_PREFIX "CopyRegionFallback",          \
196b8e80941Smrg   SVGA_STATS_PREFIX "CreateBackedSurfaceView",     \
197b8e80941Smrg   SVGA_STATS_PREFIX "CreateBuffer",                \
198b8e80941Smrg   SVGA_STATS_PREFIX "CreateContext",               \
199b8e80941Smrg   SVGA_STATS_PREFIX "CreateFS",                    \
200b8e80941Smrg   SVGA_STATS_PREFIX "CreateGS",                    \
201b8e80941Smrg   SVGA_STATS_PREFIX "CreateSurface",               \
202b8e80941Smrg   SVGA_STATS_PREFIX "CreateSurfaceView",           \
203b8e80941Smrg   SVGA_STATS_PREFIX "CreateTexture",               \
204b8e80941Smrg   SVGA_STATS_PREFIX "CreateVS",                    \
205b8e80941Smrg   SVGA_STATS_PREFIX "DefineShader",                \
206b8e80941Smrg   SVGA_STATS_PREFIX "DestroySurface",              \
207b8e80941Smrg   SVGA_STATS_PREFIX "DrawVBO",                     \
208b8e80941Smrg   SVGA_STATS_PREFIX "DrawArrays",                  \
209b8e80941Smrg   SVGA_STATS_PREFIX "DrawElements",                \
210b8e80941Smrg   SVGA_STATS_PREFIX "EmitFS",                      \
211b8e80941Smrg   SVGA_STATS_PREFIX "EmitGS",                      \
212b8e80941Smrg   SVGA_STATS_PREFIX "EmitVS",                      \
213b8e80941Smrg   SVGA_STATS_PREFIX "EmulateSurfaceView",          \
214b8e80941Smrg   SVGA_STATS_PREFIX "FenceFinish",                 \
215b8e80941Smrg   SVGA_STATS_PREFIX "GenerateIndices",             \
216b8e80941Smrg   SVGA_STATS_PREFIX "HWtnlDrawArrays",             \
217b8e80941Smrg   SVGA_STATS_PREFIX "HWtnlDrawElements",           \
218b8e80941Smrg   SVGA_STATS_PREFIX "HWtnlFlush",                  \
219b8e80941Smrg   SVGA_STATS_PREFIX "HWtnlPrim",                   \
220b8e80941Smrg   SVGA_STATS_PREFIX "PropagateSurface",            \
221b8e80941Smrg   SVGA_STATS_PREFIX "SetSamplerViews",             \
222b8e80941Smrg   SVGA_STATS_PREFIX "SurfaceFlush",                \
223b8e80941Smrg   SVGA_STATS_PREFIX "SwtnlDrawVBO",                \
224b8e80941Smrg   SVGA_STATS_PREFIX "SwtnlUpdateDraw",             \
225b8e80941Smrg   SVGA_STATS_PREFIX "SwtnlUpdateVDecl",            \
226b8e80941Smrg   SVGA_STATS_PREFIX "TextureTransferMap",          \
227b8e80941Smrg   SVGA_STATS_PREFIX "TextureTransferUnmap",        \
228b8e80941Smrg   SVGA_STATS_PREFIX "TGSIVGPU10Translate",         \
229b8e80941Smrg   SVGA_STATS_PREFIX "TGSIVGPU9Translate",          \
230b8e80941Smrg   SVGA_STATS_PREFIX "UpdateState",                 \
231b8e80941Smrg   SVGA_STATS_PREFIX "ValidateSurfaceView",         \
232b8e80941Smrg   SVGA_STATS_PREFIX "VbufDrawArrays",              \
233b8e80941Smrg   SVGA_STATS_PREFIX "VbufDrawElements",            \
234b8e80941Smrg   SVGA_STATS_PREFIX "VbufRenderAllocVertices",     \
235b8e80941Smrg   SVGA_STATS_PREFIX "VbufRenderMapVertices",       \
236b8e80941Smrg   SVGA_STATS_PREFIX "VbufRenderUnmapVertices",     \
237b8e80941Smrg   SVGA_STATS_PREFIX "VbufSubmitState"
238b8e80941Smrg
239848b8605Smrg
240848b8605Smrg/** Opaque surface handle */
241848b8605Smrgstruct svga_winsys_surface;
242848b8605Smrg
243848b8605Smrg/** Opaque guest-backed objects */
244848b8605Smrgstruct svga_winsys_gb_shader;
245b8e80941Smrgstruct svga_winsys_gb_query;
246848b8605Smrg
247848b8605Smrg
248848b8605Smrg/**
249848b8605Smrg * SVGA per-context winsys interface.
250848b8605Smrg */
251848b8605Smrgstruct svga_winsys_context
252848b8605Smrg{
253848b8605Smrg   void
254848b8605Smrg   (*destroy)(struct svga_winsys_context *swc);
255848b8605Smrg
256b8e80941Smrg   void *
257b8e80941Smrg   (*reserve)(struct svga_winsys_context *swc,
258b8e80941Smrg              uint32_t nr_bytes, uint32_t nr_relocs );
259b8e80941Smrg
260b8e80941Smrg   /**
261b8e80941Smrg    * Returns current size of command buffer, in bytes.
262b8e80941Smrg    */
263b8e80941Smrg   unsigned
264b8e80941Smrg   (*get_command_buffer_size)(struct svga_winsys_context *swc);
265b8e80941Smrg
266848b8605Smrg   /**
267848b8605Smrg    * Emit a relocation for a host surface.
268b8e80941Smrg    *
269848b8605Smrg    * @param flags bitmask of SVGA_RELOC_* flags
270b8e80941Smrg    *
271848b8605Smrg    * NOTE: Order of this call does matter. It should be the same order
272848b8605Smrg    * as relocations appear in the command buffer.
273848b8605Smrg    */
274848b8605Smrg   void
275b8e80941Smrg   (*surface_relocation)(struct svga_winsys_context *swc,
276b8e80941Smrg                         uint32 *sid,
277848b8605Smrg                         uint32 *mobid,
278b8e80941Smrg                         struct svga_winsys_surface *surface,
279b8e80941Smrg                         unsigned flags);
280b8e80941Smrg
281848b8605Smrg   /**
282848b8605Smrg    * Emit a relocation for a guest memory region.
283b8e80941Smrg    *
284848b8605Smrg    * @param flags bitmask of SVGA_RELOC_* flags
285b8e80941Smrg    *
286848b8605Smrg    * NOTE: Order of this call does matter. It should be the same order
287848b8605Smrg    * as relocations appear in the command buffer.
288848b8605Smrg    */
289848b8605Smrg   void
290b8e80941Smrg   (*region_relocation)(struct svga_winsys_context *swc,
291b8e80941Smrg                        struct SVGAGuestPtr *ptr,
292b8e80941Smrg                        struct svga_winsys_buffer *buffer,
293b8e80941Smrg                        uint32 offset,
294848b8605Smrg                        unsigned flags);
295848b8605Smrg
296848b8605Smrg   /**
297848b8605Smrg    * Emit a relocation for a guest-backed shader object.
298b8e80941Smrg    *
299848b8605Smrg    * NOTE: Order of this call does matter. It should be the same order
300848b8605Smrg    * as relocations appear in the command buffer.
301848b8605Smrg    */
302848b8605Smrg   void
303b8e80941Smrg   (*shader_relocation)(struct svga_winsys_context *swc,
304b8e80941Smrg                        uint32 *shid,
305b8e80941Smrg                        uint32 *mobid,
306b8e80941Smrg                        uint32 *offset,
307b8e80941Smrg                        struct svga_winsys_gb_shader *shader,
308b8e80941Smrg                        unsigned flags);
309848b8605Smrg
310848b8605Smrg   /**
311848b8605Smrg    * Emit a relocation for a guest-backed context.
312b8e80941Smrg    *
313848b8605Smrg    * NOTE: Order of this call does matter. It should be the same order
314848b8605Smrg    * as relocations appear in the command buffer.
315848b8605Smrg    */
316848b8605Smrg   void
317848b8605Smrg   (*context_relocation)(struct svga_winsys_context *swc, uint32 *cid);
318848b8605Smrg
319848b8605Smrg   /**
320848b8605Smrg    * Emit a relocation for a guest Memory OBject.
321848b8605Smrg    *
322848b8605Smrg    * @param flags bitmask of SVGA_RELOC_* flags
323848b8605Smrg    * @param offset_into_mob Buffer starts at this offset into the MOB.
324848b8605Smrg    *
325848b8605Smrg    * Note that not all commands accept an offset into the MOB and
326848b8605Smrg    * those commands can't use suballocated buffer pools. To trap
327848b8605Smrg    * errors from improper buffer pool usage, set the offset_into_mob
328848b8605Smrg    * pointer to NULL.
329848b8605Smrg    */
330848b8605Smrg   void
331848b8605Smrg   (*mob_relocation)(struct svga_winsys_context *swc,
332b8e80941Smrg                     SVGAMobId *id,
333b8e80941Smrg                     uint32 *offset_into_mob,
334b8e80941Smrg                     struct svga_winsys_buffer *buffer,
335b8e80941Smrg                     uint32 offset,
336b8e80941Smrg                     unsigned flags);
337b8e80941Smrg
338b8e80941Smrg   /**
339b8e80941Smrg    * Emit a relocation for a guest-backed query object.
340b8e80941Smrg    *
341b8e80941Smrg    * NOTE: Order of this call does matter. It should be the same order
342b8e80941Smrg    * as relocations appear in the command buffer.
343b8e80941Smrg    */
344b8e80941Smrg   void
345b8e80941Smrg   (*query_relocation)(struct svga_winsys_context *swc,
346b8e80941Smrg                       SVGAMobId *id,
347b8e80941Smrg                       struct svga_winsys_gb_query *query);
348b8e80941Smrg
349b8e80941Smrg   /**
350b8e80941Smrg    * Bind queries to context.
351b8e80941Smrg    * \param flags  exactly one of SVGA_QUERY_FLAG_SET/REF
352b8e80941Smrg    */
353b8e80941Smrg   enum pipe_error
354b8e80941Smrg   (*query_bind)(struct svga_winsys_context *sws,
355b8e80941Smrg                 struct svga_winsys_gb_query *query,
356b8e80941Smrg                 unsigned flags);
357848b8605Smrg
358848b8605Smrg   void
359848b8605Smrg   (*commit)(struct svga_winsys_context *swc);
360b8e80941Smrg
361848b8605Smrg   enum pipe_error
362b8e80941Smrg   (*flush)(struct svga_winsys_context *swc,
363b8e80941Smrg            struct pipe_fence_handle **pfence);
364848b8605Smrg
365b8e80941Smrg   /**
366848b8605Smrg    * Context ID used to fill in the commands
367b8e80941Smrg    *
368848b8605Smrg    * Context IDs are arbitrary small non-negative integers,
369848b8605Smrg    * global to the entire SVGA device.
370848b8605Smrg    */
371848b8605Smrg   uint32 cid;
372848b8605Smrg
373b8e80941Smrg   /**
374b8e80941Smrg    * Flags to hint the current context state
375b8e80941Smrg    */
376b8e80941Smrg   uint32 hints;
377b8e80941Smrg
378b8e80941Smrg   /**
379b8e80941Smrg    * File descriptor for imported fence
380b8e80941Smrg    */
381b8e80941Smrg   int32 imported_fence_fd;
382b8e80941Smrg
383848b8605Smrg   /**
384848b8605Smrg    ** BEGIN new functions for guest-backed surfaces.
385848b8605Smrg    **/
386848b8605Smrg
387848b8605Smrg   boolean have_gb_objects;
388848b8605Smrg
389848b8605Smrg   /**
390848b8605Smrg    * Map a guest-backed surface.
391848b8605Smrg    * \param flags  bitmaks of PIPE_TRANSFER_x flags
392848b8605Smrg    *
393848b8605Smrg    * The surface_map() member is allowed to fail due to a
394848b8605Smrg    * shortage of command buffer space, if the
395848b8605Smrg    * PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE bit is set in flags.
396848b8605Smrg    * In that case, the caller must flush the current command
397848b8605Smrg    * buffer and reissue the map.
398848b8605Smrg    */
399848b8605Smrg   void *
400848b8605Smrg   (*surface_map)(struct svga_winsys_context *swc,
401848b8605Smrg                  struct svga_winsys_surface *surface,
402848b8605Smrg                  unsigned flags, boolean *retry);
403848b8605Smrg
404848b8605Smrg   /**
405848b8605Smrg    * Unmap a guest-backed surface.
406848b8605Smrg    * \param rebind  returns a flag indicating whether the caller should
407848b8605Smrg    *                issue a SVGA3D_BindGBSurface() call.
408848b8605Smrg    */
409848b8605Smrg   void
410848b8605Smrg   (*surface_unmap)(struct svga_winsys_context *swc,
411848b8605Smrg                    struct svga_winsys_surface *surface,
412848b8605Smrg                    boolean *rebind);
413848b8605Smrg
414b8e80941Smrg   /**
415b8e80941Smrg    * Invalidate the content of this surface
416b8e80941Smrg    */
417b8e80941Smrg   enum pipe_error
418b8e80941Smrg   (*surface_invalidate)(struct svga_winsys_context *swc,
419b8e80941Smrg                         struct svga_winsys_surface *surface);
420b8e80941Smrg
421b8e80941Smrg   /**
422b8e80941Smrg    * Create and define a DX GB shader that resides in the device COTable.
423b8e80941Smrg    * Caller of this function will issue the DXDefineShader command.
424b8e80941Smrg    */
425b8e80941Smrg   struct svga_winsys_gb_shader *
426b8e80941Smrg   (*shader_create)(struct svga_winsys_context *swc,
427b8e80941Smrg                    uint32 shaderId,
428b8e80941Smrg                    SVGA3dShaderType shaderType,
429b8e80941Smrg                    const uint32 *bytecode,
430b8e80941Smrg                    uint32 bytecodeLen);
431b8e80941Smrg
432b8e80941Smrg   /**
433b8e80941Smrg    * Destroy a DX GB shader.
434b8e80941Smrg    * This function will issue the DXDestroyShader command.
435b8e80941Smrg    */
436b8e80941Smrg   void
437b8e80941Smrg   (*shader_destroy)(struct svga_winsys_context *swc,
438b8e80941Smrg                     struct svga_winsys_gb_shader *shader);
439b8e80941Smrg
440b8e80941Smrg   /**
441b8e80941Smrg    * Rebind a DX GB resource to a context.
442b8e80941Smrg    * This is called to reference a DX GB resource in the command stream in
443b8e80941Smrg    * order to page in the associated resource in case the memory has been
444b8e80941Smrg    * paged out, and to fence it if necessary after command submission.
445b8e80941Smrg    */
446b8e80941Smrg   enum pipe_error
447b8e80941Smrg   (*resource_rebind)(struct svga_winsys_context *swc,
448b8e80941Smrg                      struct svga_winsys_surface *surface,
449b8e80941Smrg                      struct svga_winsys_gb_shader *shader,
450b8e80941Smrg                      unsigned flags);
451b8e80941Smrg
452b8e80941Smrg   /** To report perf/conformance/etc issues to the state tracker */
453b8e80941Smrg   struct pipe_debug_callback *debug_callback;
454b8e80941Smrg
455b8e80941Smrg   /** The more recent command issued to command buffer */
456b8e80941Smrg   SVGAFifo3dCmdId last_command;
457b8e80941Smrg
458b8e80941Smrg   /** For HUD queries */
459b8e80941Smrg   uint64_t num_commands;
460b8e80941Smrg   uint64_t num_draw_commands;
461848b8605Smrg};
462848b8605Smrg
463848b8605Smrg
464848b8605Smrg/**
465848b8605Smrg * SVGA per-screen winsys interface.
466848b8605Smrg */
467848b8605Smrgstruct svga_winsys_screen
468848b8605Smrg{
469848b8605Smrg   void
470848b8605Smrg   (*destroy)(struct svga_winsys_screen *sws);
471b8e80941Smrg
472848b8605Smrg   SVGA3dHardwareVersion
473848b8605Smrg   (*get_hw_version)(struct svga_winsys_screen *sws);
474848b8605Smrg
475848b8605Smrg   boolean
476848b8605Smrg   (*get_cap)(struct svga_winsys_screen *sws,
477848b8605Smrg              SVGA3dDevCapIndex index,
478848b8605Smrg              SVGA3dDevCapResult *result);
479b8e80941Smrg
480848b8605Smrg   /**
481848b8605Smrg    * Create a new context.
482848b8605Smrg    *
483848b8605Smrg    * Context objects encapsulate all render state, and shader
484848b8605Smrg    * objects are per-context.
485848b8605Smrg    *
486848b8605Smrg    * Surfaces are not per-context. The same surface can be shared
487848b8605Smrg    * between multiple contexts, and surface operations can occur
488848b8605Smrg    * without a context.
489848b8605Smrg    */
490848b8605Smrg   struct svga_winsys_context *
491848b8605Smrg   (*context_create)(struct svga_winsys_screen *sws);
492b8e80941Smrg
493848b8605Smrg   /**
494848b8605Smrg    * This creates a "surface" object in the SVGA3D device.
495848b8605Smrg    *
496848b8605Smrg    * \param sws Pointer to an svga_winsys_context
497848b8605Smrg    * \param flags Device surface create flags
498848b8605Smrg    * \param format Format Device surface format
499848b8605Smrg    * \param usage Winsys usage: bitmask of SVGA_SURFACE_USAGE_x flags
500848b8605Smrg    * \param size Surface size given in device format
501b8e80941Smrg    * \param numLayers Number of layers of the surface (or cube faces)
502848b8605Smrg    * \param numMipLevels Number of mipmap levels for each face
503848b8605Smrg    *
504848b8605Smrg    * Returns the surface ID (sid). Surfaces are generic
505848b8605Smrg    * containers for host VRAM objects like textures, vertex
506848b8605Smrg    * buffers, and depth/stencil buffers.
507848b8605Smrg    *
508848b8605Smrg    * Surfaces are hierarchial:
509848b8605Smrg    *
510848b8605Smrg    * - Surface may have multiple faces (for cube maps)
511848b8605Smrg    *
512848b8605Smrg    * - Each face has a list of mipmap levels
513848b8605Smrg    *
514848b8605Smrg    * - Each mipmap image may have multiple volume
515b8e80941Smrg    *   slices for 3D image, or multiple 2D slices for texture array.
516848b8605Smrg    *
517848b8605Smrg    * - Each slice is a 2D array of 'blocks'
518848b8605Smrg    *
519848b8605Smrg    * - Each block may be one or more pixels.
520848b8605Smrg    *   (Usually 1, more for DXT or YUV formats.)
521848b8605Smrg    *
522848b8605Smrg    * Surfaces are generic host VRAM objects. The SVGA3D device
523848b8605Smrg    * may optimize surfaces according to the format they were
524848b8605Smrg    * created with, but this format does not limit the ways in
525848b8605Smrg    * which the surface may be used. For example, a depth surface
526848b8605Smrg    * can be used as a texture, or a floating point image may
527848b8605Smrg    * be used as a vertex buffer. Some surface usages may be
528848b8605Smrg    * lower performance, due to software emulation, but any
529848b8605Smrg    * usage should work with any surface.
530848b8605Smrg    */
531848b8605Smrg   struct svga_winsys_surface *
532848b8605Smrg   (*surface_create)(struct svga_winsys_screen *sws,
533b8e80941Smrg                     SVGA3dSurfaceAllFlags flags,
534848b8605Smrg                     SVGA3dSurfaceFormat format,
535848b8605Smrg                     unsigned usage,
536848b8605Smrg                     SVGA3dSize size,
537b8e80941Smrg                     uint32 numLayers,
538b8e80941Smrg                     uint32 numMipLevels,
539b8e80941Smrg                     unsigned sampleCount);
540848b8605Smrg
541848b8605Smrg   /**
542848b8605Smrg    * Creates a surface from a winsys handle.
543848b8605Smrg    * Used to implement pipe_screen::resource_from_handle.
544848b8605Smrg    */
545848b8605Smrg   struct svga_winsys_surface *
546848b8605Smrg   (*surface_from_handle)(struct svga_winsys_screen *sws,
547848b8605Smrg                          struct winsys_handle *whandle,
548848b8605Smrg                          SVGA3dSurfaceFormat *format);
549848b8605Smrg
550848b8605Smrg   /**
551848b8605Smrg    * Get a winsys_handle from a surface.
552848b8605Smrg    * Used to implement pipe_screen::resource_get_handle.
553848b8605Smrg    */
554848b8605Smrg   boolean
555848b8605Smrg   (*surface_get_handle)(struct svga_winsys_screen *sws,
556848b8605Smrg                         struct svga_winsys_surface *surface,
557848b8605Smrg                         unsigned stride,
558848b8605Smrg                         struct winsys_handle *whandle);
559848b8605Smrg
560848b8605Smrg   /**
561848b8605Smrg    * Whether this surface is sitting in a validate list
562848b8605Smrg    */
563848b8605Smrg   boolean
564848b8605Smrg   (*surface_is_flushed)(struct svga_winsys_screen *sws,
565848b8605Smrg                         struct svga_winsys_surface *surface);
566848b8605Smrg
567848b8605Smrg   /**
568848b8605Smrg    * Reference a SVGA3D surface object. This allows sharing of a
569848b8605Smrg    * surface between different objects.
570848b8605Smrg    */
571b8e80941Smrg   void
572848b8605Smrg   (*surface_reference)(struct svga_winsys_screen *sws,
573b8e80941Smrg                        struct svga_winsys_surface **pdst,
574b8e80941Smrg                        struct svga_winsys_surface *src);
575848b8605Smrg
576848b8605Smrg   /**
577848b8605Smrg    * Check if a resource (texture, buffer) of the given size
578848b8605Smrg    * and format can be created.
579848b8605Smrg    * \Return TRUE if OK, FALSE if too large.
580848b8605Smrg    */
581848b8605Smrg   boolean
582848b8605Smrg   (*surface_can_create)(struct svga_winsys_screen *sws,
583848b8605Smrg                         SVGA3dSurfaceFormat format,
584848b8605Smrg                         SVGA3dSize size,
585b8e80941Smrg                         uint32 numLayers,
586b8e80941Smrg                         uint32 numMipLevels,
587b8e80941Smrg                         uint32 numSamples);
588848b8605Smrg
589848b8605Smrg   /**
590848b8605Smrg    * Buffer management. Buffer attributes are mostly fixed over its lifetime.
591848b8605Smrg    *
592848b8605Smrg    * @param usage bitmask of SVGA_BUFFER_USAGE_* flags.
593848b8605Smrg    *
594848b8605Smrg    * alignment indicates the client's alignment requirements, eg for
595848b8605Smrg    * SSE instructions.
596848b8605Smrg    */
597848b8605Smrg   struct svga_winsys_buffer *
598b8e80941Smrg   (*buffer_create)( struct svga_winsys_screen *sws,
599b8e80941Smrg                     unsigned alignment,
600b8e80941Smrg                     unsigned usage,
601b8e80941Smrg                     unsigned size );
602848b8605Smrg
603b8e80941Smrg   /**
604848b8605Smrg    * Map the entire data store of a buffer object into the client's address.
605848b8605Smrg    * usage is a bitmask of PIPE_TRANSFER_*
606848b8605Smrg    */
607848b8605Smrg   void *
608b8e80941Smrg   (*buffer_map)( struct svga_winsys_screen *sws,
609b8e80941Smrg                  struct svga_winsys_buffer *buf,
610b8e80941Smrg                  unsigned usage );
611b8e80941Smrg
612b8e80941Smrg   void
613b8e80941Smrg   (*buffer_unmap)( struct svga_winsys_screen *sws,
614848b8605Smrg                    struct svga_winsys_buffer *buf );
615848b8605Smrg
616b8e80941Smrg   void
617848b8605Smrg   (*buffer_destroy)( struct svga_winsys_screen *sws,
618b8e80941Smrg                      struct svga_winsys_buffer *buf );
619848b8605Smrg
620848b8605Smrg
621848b8605Smrg   /**
622848b8605Smrg    * Reference a fence object.
623848b8605Smrg    */
624848b8605Smrg   void
625848b8605Smrg   (*fence_reference)( struct svga_winsys_screen *sws,
626848b8605Smrg                       struct pipe_fence_handle **pdst,
627848b8605Smrg                       struct pipe_fence_handle *src );
628848b8605Smrg
629848b8605Smrg   /**
630848b8605Smrg    * Checks whether the fence has been signalled.
631848b8605Smrg    * \param flags  driver-specific meaning
632848b8605Smrg    * \return zero on success.
633848b8605Smrg    */
634848b8605Smrg   int (*fence_signalled)( struct svga_winsys_screen *sws,
635848b8605Smrg                           struct pipe_fence_handle *fence,
636848b8605Smrg                           unsigned flag );
637848b8605Smrg
638848b8605Smrg   /**
639848b8605Smrg    * Wait for the fence to finish.
640b8e80941Smrg    * \param timeout in nanoseconds (may be PIPE_TIMEOUT_INFINITE).
641b8e80941Smrg    *                0 to return immediately, if the API suports it.
642848b8605Smrg    * \param flags  driver-specific meaning
643848b8605Smrg    * \return zero on success.
644848b8605Smrg    */
645848b8605Smrg   int (*fence_finish)( struct svga_winsys_screen *sws,
646848b8605Smrg                        struct pipe_fence_handle *fence,
647b8e80941Smrg                        uint64_t timeout,
648848b8605Smrg                        unsigned flag );
649848b8605Smrg
650b8e80941Smrg   /**
651b8e80941Smrg    * Get the file descriptor associated with the fence
652b8e80941Smrg    * \param duplicate duplicate the fd before returning it
653b8e80941Smrg    * \return zero on success.
654b8e80941Smrg    */
655b8e80941Smrg   int (*fence_get_fd)( struct svga_winsys_screen *sws,
656b8e80941Smrg                        struct pipe_fence_handle *fence,
657b8e80941Smrg                        boolean duplicate );
658b8e80941Smrg
659b8e80941Smrg   /**
660b8e80941Smrg    * Create a fence using the given file descriptor
661b8e80941Smrg    * \return zero on success.
662b8e80941Smrg    */
663b8e80941Smrg   void (*fence_create_fd)( struct svga_winsys_screen *sws,
664b8e80941Smrg                            struct pipe_fence_handle **fence,
665b8e80941Smrg                            int32_t fd );
666b8e80941Smrg
667b8e80941Smrg   /**
668b8e80941Smrg    * Accumulates fence FD from other devices into the current context
669b8e80941Smrg    * \param context_fd FD the context will be waiting on
670b8e80941Smrg    * \return zero on success
671b8e80941Smrg    */
672b8e80941Smrg   int (*fence_server_sync)( struct svga_winsys_screen *sws,
673b8e80941Smrg                             int32_t *context_fd,
674b8e80941Smrg                             struct pipe_fence_handle *fence );
675848b8605Smrg
676848b8605Smrg   /**
677848b8605Smrg    ** BEGIN new functions for guest-backed surfaces.
678848b8605Smrg    **/
679848b8605Smrg
680848b8605Smrg   /** Are guest-backed objects enabled? */
681848b8605Smrg   bool have_gb_objects;
682848b8605Smrg
683848b8605Smrg   /** Can we do DMA with guest-backed objects enabled? */
684848b8605Smrg   bool have_gb_dma;
685848b8605Smrg
686848b8605Smrg   /**
687848b8605Smrg    * Create and define a GB shader.
688848b8605Smrg    */
689848b8605Smrg   struct svga_winsys_gb_shader *
690848b8605Smrg   (*shader_create)(struct svga_winsys_screen *sws,
691b8e80941Smrg                    SVGA3dShaderType shaderType,
692b8e80941Smrg                    const uint32 *bytecode,
693b8e80941Smrg                    uint32 bytecodeLen);
694848b8605Smrg
695848b8605Smrg   /**
696848b8605Smrg    * Destroy a GB shader. It's safe to call this function even
697848b8605Smrg    * if the shader is referenced in a context's command stream.
698848b8605Smrg    */
699848b8605Smrg   void
700848b8605Smrg   (*shader_destroy)(struct svga_winsys_screen *sws,
701b8e80941Smrg                     struct svga_winsys_gb_shader *shader);
702b8e80941Smrg
703b8e80941Smrg   /**
704b8e80941Smrg    * Create and define a GB query.
705b8e80941Smrg    */
706b8e80941Smrg   struct svga_winsys_gb_query *
707b8e80941Smrg   (*query_create)(struct svga_winsys_screen *sws, uint32 len);
708b8e80941Smrg
709b8e80941Smrg   /**
710b8e80941Smrg    * Destroy a GB query.
711b8e80941Smrg    */
712b8e80941Smrg   void
713b8e80941Smrg   (*query_destroy)(struct svga_winsys_screen *sws,
714b8e80941Smrg                    struct svga_winsys_gb_query *query);
715b8e80941Smrg
716b8e80941Smrg   /**
717b8e80941Smrg    * Initialize the query state of the query that resides in the slot
718b8e80941Smrg    * specified in offset
719b8e80941Smrg    * \return zero on success.
720b8e80941Smrg    */
721b8e80941Smrg   int
722b8e80941Smrg   (*query_init)(struct svga_winsys_screen *sws,
723b8e80941Smrg                       struct svga_winsys_gb_query *query,
724b8e80941Smrg                       unsigned offset,
725b8e80941Smrg                       SVGA3dQueryState queryState);
726b8e80941Smrg
727b8e80941Smrg   /**
728b8e80941Smrg    * Inquire for the query state and result of the query that resides
729b8e80941Smrg    * in the slot specified in offset
730b8e80941Smrg    */
731b8e80941Smrg   void
732b8e80941Smrg   (*query_get_result)(struct svga_winsys_screen *sws,
733b8e80941Smrg                       struct svga_winsys_gb_query *query,
734b8e80941Smrg                       unsigned offset,
735b8e80941Smrg                       SVGA3dQueryState *queryState,
736b8e80941Smrg                       void *result, uint32 resultLen);
737b8e80941Smrg
738b8e80941Smrg   /**
739b8e80941Smrg    * Increment a statistic counter
740b8e80941Smrg    */
741b8e80941Smrg   void
742b8e80941Smrg   (*stats_inc)(enum svga_stats_count);
743b8e80941Smrg
744b8e80941Smrg   /**
745b8e80941Smrg    * Push a time frame onto the stack
746b8e80941Smrg    */
747b8e80941Smrg   void
748b8e80941Smrg   (*stats_time_push)(enum svga_stats_time, struct svga_winsys_stats_timeframe *);
749b8e80941Smrg
750b8e80941Smrg   /**
751b8e80941Smrg    * Pop a time frame.
752b8e80941Smrg    */
753b8e80941Smrg   void
754b8e80941Smrg   (*stats_time_pop)();
755b8e80941Smrg
756b8e80941Smrg   /**
757b8e80941Smrg    * Send a host log message
758b8e80941Smrg    */
759b8e80941Smrg   void
760b8e80941Smrg   (*host_log)(struct svga_winsys_screen *sws, const char *message);
761b8e80941Smrg
762b8e80941Smrg   /** Have VGPU v10 hardware? */
763b8e80941Smrg   boolean have_vgpu10;
764b8e80941Smrg
765b8e80941Smrg   /** Have SM4_1 hardware? */
766b8e80941Smrg   boolean have_sm4_1;
767b8e80941Smrg
768b8e80941Smrg   /** To rebind resources at the beginnning of a new command buffer */
769b8e80941Smrg   boolean need_to_rebind_resources;
770848b8605Smrg
771b8e80941Smrg   boolean have_generate_mipmap_cmd;
772b8e80941Smrg   boolean have_set_predication_cmd;
773b8e80941Smrg   boolean have_transfer_from_buffer_cmd;
774b8e80941Smrg   boolean have_fence_fd;
775b8e80941Smrg   boolean have_intra_surface_copy;
776848b8605Smrg};
777848b8605Smrg
778848b8605Smrg
779848b8605Smrgstruct svga_winsys_screen *
780848b8605Smrgsvga_winsys_screen(struct pipe_screen *screen);
781848b8605Smrg
782848b8605Smrgstruct svga_winsys_context *
783848b8605Smrgsvga_winsys_context(struct pipe_context *context);
784848b8605Smrg
785848b8605Smrgstruct pipe_resource *
786848b8605Smrgsvga_screen_buffer_wrap_surface(struct pipe_screen *screen,
787b8e80941Smrg                                enum SVGA3dSurfaceFormat format,
788b8e80941Smrg                                struct svga_winsys_surface *srf);
789848b8605Smrg
790848b8605Smrgstruct svga_winsys_surface *
791848b8605Smrgsvga_screen_buffer_get_winsys_surface(struct pipe_resource *buffer);
792848b8605Smrg
793848b8605Smrg#endif /* SVGA_WINSYS_H_ */
794