svga: Rename SVGA_HINT_FLAG_DRAW_EMITTED
[mesa.git] / src / gallium / drivers / svga / svga_winsys.h
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
39 #include "svga_types.h"
40 #include "svga_reg.h"
41 #include "svga3d_reg.h"
42
43 #include "pipe/p_compiler.h"
44 #include "pipe/p_defines.h"
45
46
47 struct svga_winsys_screen;
48 struct svga_winsys_buffer;
49 struct pipe_screen;
50 struct pipe_context;
51 struct pipe_fence_handle;
52 struct pipe_resource;
53 struct svga_region;
54 struct winsys_handle;
55
56
57 #define SVGA_BUFFER_USAGE_PINNED (1 << 0)
58 #define SVGA_BUFFER_USAGE_WRAPPED (1 << 1)
59 #define SVGA_BUFFER_USAGE_SHADER (1 << 2)
60
61 /**
62 * Relocation flags to help with dirty tracking
63 * SVGA_RELOC_WRITE - The command will cause a GPU write to this
64 * resource.
65 * SVGA_RELOC_READ - The command will cause a GPU read from this
66 * resource.
67 * SVGA_RELOC_INTERNAL The command will only transfer data internally
68 * within the resource, and optionally clear
69 * dirty bits
70 * SVGA_RELOC_DMA - Only set for resource buffer DMA uploads for winsys
71 * implementations that want to track the amount
72 * of such data referenced in the command stream.
73 */
74 #define SVGA_RELOC_WRITE (1 << 0)
75 #define SVGA_RELOC_READ (1 << 1)
76 #define SVGA_RELOC_INTERNAL (1 << 2)
77 #define SVGA_RELOC_DMA (1 << 3)
78
79 #define SVGA_FENCE_FLAG_EXEC (1 << 0)
80 #define SVGA_FENCE_FLAG_QUERY (1 << 1)
81
82 #define SVGA_SURFACE_USAGE_SHARED (1 << 0)
83 #define SVGA_SURFACE_USAGE_SCANOUT (1 << 1)
84
85 #define SVGA_QUERY_FLAG_SET (1 << 0)
86 #define SVGA_QUERY_FLAG_REF (1 << 1)
87
88 #define SVGA_HINT_FLAG_CAN_PRE_FLUSH (1 << 0) /* Can preemptively flush */
89
90 /** Opaque surface handle */
91 struct svga_winsys_surface;
92
93 /** Opaque guest-backed objects */
94 struct svga_winsys_gb_shader;
95 struct svga_winsys_gb_query;
96
97
98 /**
99 * SVGA per-context winsys interface.
100 */
101 struct svga_winsys_context
102 {
103 void
104 (*destroy)(struct svga_winsys_context *swc);
105
106 void *
107 (*reserve)(struct svga_winsys_context *swc,
108 uint32_t nr_bytes, uint32_t nr_relocs );
109
110 /**
111 * Emit a relocation for a host surface.
112 *
113 * @param flags bitmask of SVGA_RELOC_* flags
114 *
115 * NOTE: Order of this call does matter. It should be the same order
116 * as relocations appear in the command buffer.
117 */
118 void
119 (*surface_relocation)(struct svga_winsys_context *swc,
120 uint32 *sid,
121 uint32 *mobid,
122 struct svga_winsys_surface *surface,
123 unsigned flags);
124
125 /**
126 * Emit a relocation for a guest memory region.
127 *
128 * @param flags bitmask of SVGA_RELOC_* flags
129 *
130 * NOTE: Order of this call does matter. It should be the same order
131 * as relocations appear in the command buffer.
132 */
133 void
134 (*region_relocation)(struct svga_winsys_context *swc,
135 struct SVGAGuestPtr *ptr,
136 struct svga_winsys_buffer *buffer,
137 uint32 offset,
138 unsigned flags);
139
140 /**
141 * Emit a relocation for a guest-backed shader object.
142 *
143 * NOTE: Order of this call does matter. It should be the same order
144 * as relocations appear in the command buffer.
145 */
146 void
147 (*shader_relocation)(struct svga_winsys_context *swc,
148 uint32 *shid,
149 uint32 *mobid,
150 uint32 *offset,
151 struct svga_winsys_gb_shader *shader,
152 unsigned flags);
153
154 /**
155 * Emit a relocation for a guest-backed context.
156 *
157 * NOTE: Order of this call does matter. It should be the same order
158 * as relocations appear in the command buffer.
159 */
160 void
161 (*context_relocation)(struct svga_winsys_context *swc, uint32 *cid);
162
163 /**
164 * Emit a relocation for a guest Memory OBject.
165 *
166 * @param flags bitmask of SVGA_RELOC_* flags
167 * @param offset_into_mob Buffer starts at this offset into the MOB.
168 *
169 * Note that not all commands accept an offset into the MOB and
170 * those commands can't use suballocated buffer pools. To trap
171 * errors from improper buffer pool usage, set the offset_into_mob
172 * pointer to NULL.
173 */
174 void
175 (*mob_relocation)(struct svga_winsys_context *swc,
176 SVGAMobId *id,
177 uint32 *offset_into_mob,
178 struct svga_winsys_buffer *buffer,
179 uint32 offset,
180 unsigned flags);
181
182 /**
183 * Emit a relocation for a guest-backed query object.
184 *
185 * NOTE: Order of this call does matter. It should be the same order
186 * as relocations appear in the command buffer.
187 */
188 void
189 (*query_relocation)(struct svga_winsys_context *swc,
190 SVGAMobId *id,
191 struct svga_winsys_gb_query *query);
192
193 /**
194 * Bind queries to context.
195 * \param flags exactly one of SVGA_QUERY_FLAG_SET/REF
196 */
197 enum pipe_error
198 (*query_bind)(struct svga_winsys_context *sws,
199 struct svga_winsys_gb_query *query,
200 unsigned flags);
201
202 void
203 (*commit)(struct svga_winsys_context *swc);
204
205 enum pipe_error
206 (*flush)(struct svga_winsys_context *swc,
207 struct pipe_fence_handle **pfence);
208
209 /**
210 * Context ID used to fill in the commands
211 *
212 * Context IDs are arbitrary small non-negative integers,
213 * global to the entire SVGA device.
214 */
215 uint32 cid;
216
217 /**
218 * Flags to hint the current context state
219 */
220 uint32 hints;
221
222 /**
223 ** BEGIN new functions for guest-backed surfaces.
224 **/
225
226 boolean have_gb_objects;
227
228 /**
229 * Map a guest-backed surface.
230 * \param flags bitmaks of PIPE_TRANSFER_x flags
231 *
232 * The surface_map() member is allowed to fail due to a
233 * shortage of command buffer space, if the
234 * PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE bit is set in flags.
235 * In that case, the caller must flush the current command
236 * buffer and reissue the map.
237 */
238 void *
239 (*surface_map)(struct svga_winsys_context *swc,
240 struct svga_winsys_surface *surface,
241 unsigned flags, boolean *retry);
242
243 /**
244 * Unmap a guest-backed surface.
245 * \param rebind returns a flag indicating whether the caller should
246 * issue a SVGA3D_BindGBSurface() call.
247 */
248 void
249 (*surface_unmap)(struct svga_winsys_context *swc,
250 struct svga_winsys_surface *surface,
251 boolean *rebind);
252
253 /**
254 * Create and define a DX GB shader that resides in the device COTable.
255 * Caller of this function will issue the DXDefineShader command.
256 */
257 struct svga_winsys_gb_shader *
258 (*shader_create)(struct svga_winsys_context *swc,
259 uint32 shaderId,
260 SVGA3dShaderType shaderType,
261 const uint32 *bytecode,
262 uint32 bytecodeLen);
263
264 /**
265 * Destroy a DX GB shader.
266 * This function will issue the DXDestroyShader command.
267 */
268 void
269 (*shader_destroy)(struct svga_winsys_context *swc,
270 struct svga_winsys_gb_shader *shader);
271
272 /**
273 * Rebind a DX GB resource to a context.
274 * This is called to reference a DX GB resource in the command stream in
275 * order to page in the associated resource in case the memory has been
276 * paged out, and to fence it if necessary after command submission.
277 */
278 enum pipe_error
279 (*resource_rebind)(struct svga_winsys_context *swc,
280 struct svga_winsys_surface *surface,
281 struct svga_winsys_gb_shader *shader,
282 unsigned flags);
283 };
284
285
286 /**
287 * SVGA per-screen winsys interface.
288 */
289 struct svga_winsys_screen
290 {
291 void
292 (*destroy)(struct svga_winsys_screen *sws);
293
294 SVGA3dHardwareVersion
295 (*get_hw_version)(struct svga_winsys_screen *sws);
296
297 boolean
298 (*get_cap)(struct svga_winsys_screen *sws,
299 SVGA3dDevCapIndex index,
300 SVGA3dDevCapResult *result);
301
302 /**
303 * Create a new context.
304 *
305 * Context objects encapsulate all render state, and shader
306 * objects are per-context.
307 *
308 * Surfaces are not per-context. The same surface can be shared
309 * between multiple contexts, and surface operations can occur
310 * without a context.
311 */
312 struct svga_winsys_context *
313 (*context_create)(struct svga_winsys_screen *sws);
314
315
316 /**
317 * This creates a "surface" object in the SVGA3D device.
318 *
319 * \param sws Pointer to an svga_winsys_context
320 * \param flags Device surface create flags
321 * \param format Format Device surface format
322 * \param usage Winsys usage: bitmask of SVGA_SURFACE_USAGE_x flags
323 * \param size Surface size given in device format
324 * \param numLayers Number of layers of the surface (or cube faces)
325 * \param numMipLevels Number of mipmap levels for each face
326 *
327 * Returns the surface ID (sid). Surfaces are generic
328 * containers for host VRAM objects like textures, vertex
329 * buffers, and depth/stencil buffers.
330 *
331 * Surfaces are hierarchial:
332 *
333 * - Surface may have multiple faces (for cube maps)
334 *
335 * - Each face has a list of mipmap levels
336 *
337 * - Each mipmap image may have multiple volume
338 * slices for 3D image, or multiple 2D slices for texture array.
339 *
340 * - Each slice is a 2D array of 'blocks'
341 *
342 * - Each block may be one or more pixels.
343 * (Usually 1, more for DXT or YUV formats.)
344 *
345 * Surfaces are generic host VRAM objects. The SVGA3D device
346 * may optimize surfaces according to the format they were
347 * created with, but this format does not limit the ways in
348 * which the surface may be used. For example, a depth surface
349 * can be used as a texture, or a floating point image may
350 * be used as a vertex buffer. Some surface usages may be
351 * lower performance, due to software emulation, but any
352 * usage should work with any surface.
353 */
354 struct svga_winsys_surface *
355 (*surface_create)(struct svga_winsys_screen *sws,
356 SVGA3dSurfaceFlags flags,
357 SVGA3dSurfaceFormat format,
358 unsigned usage,
359 SVGA3dSize size,
360 uint32 numLayers,
361 uint32 numMipLevels,
362 unsigned sampleCount);
363
364 /**
365 * Creates a surface from a winsys handle.
366 * Used to implement pipe_screen::resource_from_handle.
367 */
368 struct svga_winsys_surface *
369 (*surface_from_handle)(struct svga_winsys_screen *sws,
370 struct winsys_handle *whandle,
371 SVGA3dSurfaceFormat *format);
372
373 /**
374 * Get a winsys_handle from a surface.
375 * Used to implement pipe_screen::resource_get_handle.
376 */
377 boolean
378 (*surface_get_handle)(struct svga_winsys_screen *sws,
379 struct svga_winsys_surface *surface,
380 unsigned stride,
381 struct winsys_handle *whandle);
382
383 /**
384 * Whether this surface is sitting in a validate list
385 */
386 boolean
387 (*surface_is_flushed)(struct svga_winsys_screen *sws,
388 struct svga_winsys_surface *surface);
389
390 /**
391 * Reference a SVGA3D surface object. This allows sharing of a
392 * surface between different objects.
393 */
394 void
395 (*surface_reference)(struct svga_winsys_screen *sws,
396 struct svga_winsys_surface **pdst,
397 struct svga_winsys_surface *src);
398
399 /**
400 * Check if a resource (texture, buffer) of the given size
401 * and format can be created.
402 * \Return TRUE if OK, FALSE if too large.
403 */
404 boolean
405 (*surface_can_create)(struct svga_winsys_screen *sws,
406 SVGA3dSurfaceFormat format,
407 SVGA3dSize size,
408 uint32 numLayers,
409 uint32 numMipLevels);
410
411 /**
412 * Buffer management. Buffer attributes are mostly fixed over its lifetime.
413 *
414 * @param usage bitmask of SVGA_BUFFER_USAGE_* flags.
415 *
416 * alignment indicates the client's alignment requirements, eg for
417 * SSE instructions.
418 */
419 struct svga_winsys_buffer *
420 (*buffer_create)( struct svga_winsys_screen *sws,
421 unsigned alignment,
422 unsigned usage,
423 unsigned size );
424
425 /**
426 * Map the entire data store of a buffer object into the client's address.
427 * usage is a bitmask of PIPE_TRANSFER_*
428 */
429 void *
430 (*buffer_map)( struct svga_winsys_screen *sws,
431 struct svga_winsys_buffer *buf,
432 unsigned usage );
433
434 void
435 (*buffer_unmap)( struct svga_winsys_screen *sws,
436 struct svga_winsys_buffer *buf );
437
438 void
439 (*buffer_destroy)( struct svga_winsys_screen *sws,
440 struct svga_winsys_buffer *buf );
441
442
443 /**
444 * Reference a fence object.
445 */
446 void
447 (*fence_reference)( struct svga_winsys_screen *sws,
448 struct pipe_fence_handle **pdst,
449 struct pipe_fence_handle *src );
450
451 /**
452 * Checks whether the fence has been signalled.
453 * \param flags driver-specific meaning
454 * \return zero on success.
455 */
456 int (*fence_signalled)( struct svga_winsys_screen *sws,
457 struct pipe_fence_handle *fence,
458 unsigned flag );
459
460 /**
461 * Wait for the fence to finish.
462 * \param flags driver-specific meaning
463 * \return zero on success.
464 */
465 int (*fence_finish)( struct svga_winsys_screen *sws,
466 struct pipe_fence_handle *fence,
467 unsigned flag );
468
469
470 /**
471 ** BEGIN new functions for guest-backed surfaces.
472 **/
473
474 /** Are guest-backed objects enabled? */
475 bool have_gb_objects;
476
477 /** Can we do DMA with guest-backed objects enabled? */
478 bool have_gb_dma;
479
480 /**
481 * Create and define a GB shader.
482 */
483 struct svga_winsys_gb_shader *
484 (*shader_create)(struct svga_winsys_screen *sws,
485 SVGA3dShaderType shaderType,
486 const uint32 *bytecode,
487 uint32 bytecodeLen);
488
489 /**
490 * Destroy a GB shader. It's safe to call this function even
491 * if the shader is referenced in a context's command stream.
492 */
493 void
494 (*shader_destroy)(struct svga_winsys_screen *sws,
495 struct svga_winsys_gb_shader *shader);
496
497 /**
498 * Create and define a GB query.
499 */
500 struct svga_winsys_gb_query *
501 (*query_create)(struct svga_winsys_screen *sws, uint32 len);
502
503 /**
504 * Destroy a GB query.
505 */
506 void
507 (*query_destroy)(struct svga_winsys_screen *sws,
508 struct svga_winsys_gb_query *query);
509
510 /**
511 * Initialize the query state of the query that resides in the slot
512 * specified in offset
513 * \return zero on success.
514 */
515 int
516 (*query_init)(struct svga_winsys_screen *sws,
517 struct svga_winsys_gb_query *query,
518 unsigned offset,
519 SVGA3dQueryState queryState);
520
521 /**
522 * Inquire for the query state and result of the query that resides
523 * in the slot specified in offset
524 */
525 void
526 (*query_get_result)(struct svga_winsys_screen *sws,
527 struct svga_winsys_gb_query *query,
528 unsigned offset,
529 SVGA3dQueryState *queryState,
530 void *result, uint32 resultLen);
531
532 /** Have VGPU v10 hardware? */
533 boolean have_vgpu10;
534
535 /** To rebind resources at the beginnning of a new command buffer */
536 boolean need_to_rebind_resources;
537 };
538
539
540 struct svga_winsys_screen *
541 svga_winsys_screen(struct pipe_screen *screen);
542
543 struct svga_winsys_context *
544 svga_winsys_context(struct pipe_context *context);
545
546 struct pipe_resource *
547 svga_screen_buffer_wrap_surface(struct pipe_screen *screen,
548 enum SVGA3dSurfaceFormat format,
549 struct svga_winsys_surface *srf);
550
551 struct svga_winsys_surface *
552 svga_screen_buffer_get_winsys_surface(struct pipe_resource *buffer);
553
554 #endif /* SVGA_WINSYS_H_ */