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