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