1 /************************************************************************** 2 * 3 * Copyright 2007 VMware, Inc. 4 * All Rights Reserved. 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a 7 * copy of this software and associated documentation files (the 8 * "Software"), to deal in the Software without restriction, including 9 * without limitation the rights to use, copy, modify, merge, publish, 10 * distribute, sub license, and/or sell copies of the Software, and to 11 * permit persons to whom the Software is furnished to do so, subject to 12 * the following conditions: 13 * 14 * The above copyright notice and this permission notice (including the 15 * next paragraph) shall be included in all copies or substantial portions 16 * of the Software. 17 * 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR 22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 * 26 **************************************************************************/ 27 28 /** 29 * @file 30 * 31 * Screen, Adapter or GPU 32 * 33 * These are driver functions/facilities that are context independent. 34 */ 35 36 37 #ifndef P_SCREEN_H 38 #define P_SCREEN_H 39 40 41 #include "util/compiler.h" 42 #include "util/format/u_formats.h" 43 #include "pipe/p_defines.h" 44 #include "pipe/p_video_enums.h" 45 46 47 48 #ifdef __cplusplus 49 extern "C" { 50 #endif 51 52 53 /** Opaque types */ 54 struct winsys_handle; 55 struct pipe_fence_handle; 56 struct pipe_resource; 57 struct pipe_surface; 58 struct pipe_transfer; 59 struct pipe_box; 60 struct pipe_memory_info; 61 struct pipe_vertex_buffer; 62 struct pipe_vertex_element; 63 struct pipe_vertex_state; 64 struct disk_cache; 65 struct driOptionCache; 66 struct u_transfer_helper; 67 struct pipe_screen; 68 struct util_queue_fence; 69 struct pipe_video_buffer; 70 71 typedef struct pipe_vertex_state * 72 (*pipe_create_vertex_state_func)(struct pipe_screen *screen, 73 struct pipe_vertex_buffer *buffer, 74 const struct pipe_vertex_element *elements, 75 unsigned num_elements, 76 struct pipe_resource *indexbuf, 77 uint32_t full_velem_mask); 78 typedef void (*pipe_vertex_state_destroy_func)(struct pipe_screen *screen, 79 struct pipe_vertex_state *); 80 typedef void (*pipe_driver_thread_func)(void *job, void *gdata, int thread_index); 81 82 83 84 /** 85 * Gallium screen/adapter context. Basically everything 86 * hardware-specific that doesn't actually require a rendering 87 * context. 88 */ 89 struct pipe_screen { 90 int refcnt; 91 void *winsys_priv; 92 93 /** 94 * Get the fd associated with the screen 95 * The fd returned is considered read-only, and in particular will not 96 * be close()d. It must remain valid for as long as the screen exists. 97 */ 98 int (*get_screen_fd)(struct pipe_screen *); 99 100 /** 101 * Atomically incremented by drivers to track the number of contexts. 102 * If it's 0, it can be assumed that contexts are not tracked. 103 * Used by some places to skip locking if num_contexts == 1. 104 */ 105 unsigned num_contexts; 106 107 /** 108 * For drivers using u_transfer_helper: 109 */ 110 struct u_transfer_helper *transfer_helper; 111 112 void (*destroy)(struct pipe_screen *); 113 114 const char *(*get_name)(struct pipe_screen *); 115 116 const char *(*get_vendor)(struct pipe_screen *); 117 118 /** 119 * Returns the device vendor. 120 * 121 * The returned value should return the actual device vendor/manufacturer, 122 * rather than a potentially generic driver string. 123 */ 124 const char *(*get_device_vendor)(struct pipe_screen *); 125 126 /** 127 * Returns the latest OpenCL CTS version passed 128 * 129 * The returned value should be the git tag used when passing conformance. 130 */ 131 const char *(*get_cl_cts_version)(struct pipe_screen *); 132 133 /** 134 * Query an integer-valued capability/parameter/limit 135 * \param param one of PIPE_CAP_x 136 */ 137 int (*get_param)(struct pipe_screen *, enum pipe_cap param); 138 139 /** 140 * Query a float-valued capability/parameter/limit 141 * \param param one of PIPE_CAP_x 142 */ 143 float (*get_paramf)(struct pipe_screen *, enum pipe_capf param); 144 145 /** 146 * Query a per-shader-stage integer-valued capability/parameter/limit 147 * \param param one of PIPE_CAP_x 148 */ 149 int (*get_shader_param)(struct pipe_screen *, enum pipe_shader_type shader, 150 enum pipe_shader_cap param); 151 152 /** 153 * Query an integer-valued capability/parameter/limit for a codec/profile 154 * \param param one of PIPE_VIDEO_CAP_x 155 */ 156 int (*get_video_param)(struct pipe_screen *, 157 enum pipe_video_profile profile, 158 enum pipe_video_entrypoint entrypoint, 159 enum pipe_video_cap param); 160 161 /** 162 * Query a compute-specific capability/parameter/limit. 163 * \param ir_type shader IR type for which the param applies, or don't care 164 * if the param is not shader related 165 * \param param one of PIPE_COMPUTE_CAP_x 166 * \param ret pointer to a preallocated buffer that will be 167 * initialized to the parameter value, or NULL. 168 * \return size in bytes of the parameter value that would be 169 * returned. 170 */ 171 int (*get_compute_param)(struct pipe_screen *, 172 enum pipe_shader_ir ir_type, 173 enum pipe_compute_cap param, 174 void *ret); 175 176 /** 177 * Get the sample pixel grid's size. This function requires 178 * PIPE_CAP_PROGRAMMABLE_SAMPLE_LOCATIONS to be callable. 179 * 180 * \param sample_count - total number of samples 181 * \param out_width - the width of the pixel grid 182 * \param out_height - the height of the pixel grid 183 */ 184 void (*get_sample_pixel_grid)(struct pipe_screen *, unsigned sample_count, 185 unsigned *out_width, unsigned *out_height); 186 187 /** 188 * Query a timestamp in nanoseconds. The returned value should match 189 * PIPE_QUERY_TIMESTAMP. This function returns immediately and doesn't 190 * wait for rendering to complete (which cannot be achieved with queries). 191 */ 192 uint64_t (*get_timestamp)(struct pipe_screen *); 193 194 /** 195 * Return an equivalent canonical format which has the same component sizes 196 * and swizzles as the original, and it is supported by the driver. Gallium 197 * already does a first canonicalization step (see get_canonical_format() 198 * on st_cb_copyimage.c) and it calls this function (if defined) to get an 199 * alternative format if the picked is not supported by the driver. 200 */ 201 enum pipe_format (*get_canonical_format)(struct pipe_screen *, 202 enum pipe_format format); 203 204 /** 205 * Create a context. 206 * 207 * \param screen pipe screen 208 * \param priv a pointer to set in pipe_context::priv 209 * \param flags a mask of PIPE_CONTEXT_* flags 210 */ 211 struct pipe_context * (*context_create)(struct pipe_screen *screen, 212 void *priv, unsigned flags); 213 214 /** 215 * Check if the given image copy will be faster on compute 216 * \param cpu If true, this is checking against CPU fallback, 217 * otherwise the copy will be on GFX 218 */ 219 bool (*is_compute_copy_faster)(struct pipe_screen *, 220 enum pipe_format src_format, 221 enum pipe_format dst_format, 222 unsigned width, 223 unsigned height, 224 unsigned depth, 225 bool cpu); 226 227 /** 228 * Check if the given pipe_format is supported as a texture or 229 * drawing surface. 230 * \param bindings bitmask of PIPE_BIND_* 231 */ 232 bool (*is_format_supported)(struct pipe_screen *, 233 enum pipe_format format, 234 enum pipe_texture_target target, 235 unsigned sample_count, 236 unsigned storage_sample_count, 237 unsigned bindings); 238 239 /** 240 * Check if the given pipe_format is supported as output for this 241 * codec/profile. 242 * \param profile profile to check, may also be PIPE_VIDEO_PROFILE_UNKNOWN 243 */ 244 bool (*is_video_format_supported)(struct pipe_screen *, 245 enum pipe_format format, 246 enum pipe_video_profile profile, 247 enum pipe_video_entrypoint entrypoint); 248 249 /** 250 * Check if we can actually create the given resource (test the dimension, 251 * overall size, etc). Used to implement proxy textures. 252 * \return TRUE if size is OK, FALSE if too large. 253 */ 254 bool (*can_create_resource)(struct pipe_screen *screen, 255 const struct pipe_resource *templat); 256 257 /** 258 * Create a new texture object, using the given template info. 259 */ 260 struct pipe_resource * (*resource_create)(struct pipe_screen *, 261 const struct pipe_resource *templat); 262 263 struct pipe_resource * (*resource_create_drawable)(struct pipe_screen *, 264 const struct pipe_resource *tmpl, 265 const void *loader_private); 266 267 struct pipe_resource * (*resource_create_front)(struct pipe_screen *, 268 const struct pipe_resource *templat, 269 const void *map_front_private); 270 271 /** 272 * Create a texture from a winsys_handle. The handle is often created in 273 * another process by first creating a pipe texture and then calling 274 * resource_get_handle. 275 * 276 * NOTE: in the case of WINSYS_HANDLE_TYPE_FD handles, the caller 277 * retains ownership of the FD. (This is consistent with 278 * EGL_EXT_image_dma_buf_import) 279 * 280 * \param usage A combination of PIPE_HANDLE_USAGE_* flags. 281 */ 282 struct pipe_resource * (*resource_from_handle)(struct pipe_screen *, 283 const struct pipe_resource *templat, 284 struct winsys_handle *handle, 285 unsigned usage); 286 287 /** 288 * Create a resource from user memory. This maps the user memory into 289 * the device address space. 290 */ 291 struct pipe_resource * (*resource_from_user_memory)(struct pipe_screen *, 292 const struct pipe_resource *t, 293 void *user_memory); 294 295 /** 296 * Unlike pipe_resource::bind, which describes what gallium frontends want, 297 * resources can have much greater capabilities in practice, often implied 298 * by the tiling layout or memory placement. This function allows querying 299 * whether a capability is supported beyond what was requested by state 300 * trackers. It's also useful for querying capabilities of imported 301 * resources where the capabilities are unknown at first. 302 * 303 * Only these flags are allowed: 304 * - PIPE_BIND_SCANOUT 305 * - PIPE_BIND_CURSOR 306 * - PIPE_BIND_LINEAR 307 */ 308 bool (*check_resource_capability)(struct pipe_screen *screen, 309 struct pipe_resource *resource, 310 unsigned bind); 311 312 /** 313 * Get a winsys_handle from a texture. Some platforms/winsys requires 314 * that the texture is created with a special usage flag like 315 * DISPLAYTARGET or PRIMARY. 316 * 317 * The context parameter can optionally be used to flush the resource and 318 * the context to make sure the resource is coherent with whatever user 319 * will use it. Some drivers may also use the context to convert 320 * the resource into a format compatible for sharing. The use case is 321 * OpenGL-OpenCL interop. The context parameter is allowed to be NULL. 322 * 323 * NOTE: for multi-planar resources (which may or may not have the planes 324 * chained through the pipe_resource next pointer) the frontend will 325 * always call this function with the first resource of the chain. It is 326 * the pipe drivers responsibility to walk the resources as needed when 327 * called with handle->plane != 0. 328 * 329 * NOTE: in the case of WINSYS_HANDLE_TYPE_FD handles, the caller 330 * takes ownership of the FD. (This is consistent with 331 * EGL_MESA_image_dma_buf_export) 332 * 333 * \param usage A combination of PIPE_HANDLE_USAGE_* flags. 334 */ 335 bool (*resource_get_handle)(struct pipe_screen *, 336 struct pipe_context *context, 337 struct pipe_resource *tex, 338 struct winsys_handle *handle, 339 unsigned usage); 340 341 /** 342 * Get info for the given pipe resource without the need to get a 343 * winsys_handle. 344 * 345 * The context parameter can optionally be used to flush the resource and 346 * the context to make sure the resource is coherent with whatever user 347 * will use it. Some drivers may also use the context to convert 348 * the resource into a format compatible for sharing. The context parameter 349 * is allowed to be NULL. 350 */ 351 bool (*resource_get_param)(struct pipe_screen *screen, 352 struct pipe_context *context, 353 struct pipe_resource *resource, 354 unsigned plane, 355 unsigned layer, 356 unsigned level, 357 enum pipe_resource_param param, 358 unsigned handle_usage, 359 uint64_t *value); 360 361 /** 362 * Get stride and offset for the given pipe resource without the need to get 363 * a winsys_handle. 364 */ 365 void (*resource_get_info)(struct pipe_screen *screen, 366 struct pipe_resource *resource, 367 unsigned *stride, 368 unsigned *offset); 369 370 /** 371 * Mark the resource as changed so derived internal resources will be 372 * recreated on next use. 373 * 374 * This is necessary when reimporting external images that can't be directly 375 * used as texture sampler source, to avoid sampling from old copies. 376 */ 377 void (*resource_changed)(struct pipe_screen *, struct pipe_resource *pt); 378 379 void (*resource_destroy)(struct pipe_screen *, 380 struct pipe_resource *pt); 381 382 383 /** 384 * Do any special operations to ensure frontbuffer contents are 385 * displayed, eg copy fake frontbuffer. 386 * \param winsys_drawable_handle an opaque handle that the calling context 387 * gets out-of-band 388 * \param nboxes the number of sub regions to flush 389 * \param subbox an array of optional sub regions to flush 390 */ 391 void (*flush_frontbuffer)(struct pipe_screen *screen, 392 struct pipe_context *ctx, 393 struct pipe_resource *resource, 394 unsigned level, unsigned layer, 395 void *winsys_drawable_handle, 396 unsigned nboxes, 397 struct pipe_box *subbox); 398 399 /** Set ptr = fence, with reference counting */ 400 void (*fence_reference)(struct pipe_screen *screen, 401 struct pipe_fence_handle **ptr, 402 struct pipe_fence_handle *fence); 403 404 /** 405 * Wait for the fence to finish. 406 * 407 * If the fence was created with PIPE_FLUSH_DEFERRED, and the context is 408 * still unflushed, and the ctx parameter of fence_finish is equal to 409 * the context where the fence was created, fence_finish will flush 410 * the context prior to waiting for the fence. 411 * 412 * In all other cases, the ctx parameter has no effect. 413 * 414 * \param timeout in nanoseconds (may be OS_TIMEOUT_INFINITE). 415 */ 416 bool (*fence_finish)(struct pipe_screen *screen, 417 struct pipe_context *ctx, 418 struct pipe_fence_handle *fence, 419 uint64_t timeout); 420 421 /** 422 * For fences created with PIPE_FLUSH_FENCE_FD (exported fd) or 423 * by create_fence_fd() (imported fd), return the native fence fd 424 * associated with the fence. This may return -1 for fences 425 * created with PIPE_FLUSH_DEFERRED if the fence command has not 426 * been flushed yet. 427 */ 428 int (*fence_get_fd)(struct pipe_screen *screen, 429 struct pipe_fence_handle *fence); 430 431 /** 432 * Retrieves the Win32 shared handle from the fence. 433 * Note that Windows fences are pretty much all timeline semaphores, 434 * so a value is needed to denote the specific point on the timeline. 435 */ 436 void* (*fence_get_win32_handle)(struct pipe_screen *screen, 437 struct pipe_fence_handle *fence, 438 uint64_t *fence_value); 439 440 /** 441 * Create a fence from an Win32 handle. 442 * 443 * This is used for importing a foreign/external fence handle. 444 * 445 * \param fence if not NULL, an old fence to unref and transfer a 446 * new fence reference to 447 * \param handle opaque handle representing the fence object 448 * \param type indicates which fence types backs the handle 449 */ 450 void (*create_fence_win32)(struct pipe_screen *screen, 451 struct pipe_fence_handle **fence, 452 void *handle, 453 const void *name, 454 enum pipe_fd_type type); 455 456 /** 457 * Returns a driver-specific query. 458 * 459 * If \p info is NULL, the number of available queries is returned. 460 * Otherwise, the driver query at the specified \p index is returned 461 * in \p info. The function returns non-zero on success. 462 */ 463 int (*get_driver_query_info)(struct pipe_screen *screen, 464 unsigned index, 465 struct pipe_driver_query_info *info); 466 467 /** 468 * Returns a driver-specific query group. 469 * 470 * If \p info is NULL, the number of available groups is returned. 471 * Otherwise, the driver query group at the specified \p index is returned 472 * in \p info. The function returns non-zero on success. 473 */ 474 int (*get_driver_query_group_info)(struct pipe_screen *screen, 475 unsigned index, 476 struct pipe_driver_query_group_info *info); 477 478 /** 479 * Query information about memory usage. 480 */ 481 void (*query_memory_info)(struct pipe_screen *screen, 482 struct pipe_memory_info *info); 483 484 /** 485 * Get IR specific compiler options struct. For PIPE_SHADER_IR_NIR this 486 * returns a 'struct nir_shader_compiler_options'. Drivers reporting 487 * NIR as the preferred IR must implement this. 488 */ 489 const void *(*get_compiler_options)(struct pipe_screen *screen, 490 enum pipe_shader_ir ir, 491 enum pipe_shader_type shader); 492 493 /** 494 * Returns a pointer to a driver-specific on-disk shader cache. If the 495 * driver failed to create the cache or does not support an on-disk shader 496 * cache NULL is returned. The callback itself may also be NULL if the 497 * driver doesn't support an on-disk shader cache. 498 */ 499 struct disk_cache *(*get_disk_shader_cache)(struct pipe_screen *screen); 500 501 /** 502 * Create a new texture object from the given template info, taking 503 * format modifiers into account. \p modifiers specifies a list of format 504 * modifier tokens, as defined in drm_fourcc.h. The driver then picks the 505 * best modifier among these and creates the resource. \p count must 506 * contain the size of \p modifiers array. 507 * 508 * Returns NULL if an entry in \p modifiers is unsupported by the driver, 509 * or if only DRM_FORMAT_MOD_INVALID is provided. 510 */ 511 struct pipe_resource * (*resource_create_with_modifiers)( 512 struct pipe_screen *, 513 const struct pipe_resource *templat, 514 const uint64_t *modifiers, int count); 515 516 /** 517 * Get supported modifiers for a format. 518 * If \p max is 0, the total number of supported modifiers for the supplied 519 * format is returned in \p count, with no modification to \p modifiers. 520 * Otherwise, \p modifiers is filled with upto \p max supported modifier 521 * codes, and \p count with the number of modifiers copied. 522 * The \p external_only array is used to return whether the format and 523 * modifier combination can only be used with an external texture target. 524 */ 525 void (*query_dmabuf_modifiers)(struct pipe_screen *screen, 526 enum pipe_format format, int max, 527 uint64_t *modifiers, 528 unsigned int *external_only, int *count); 529 530 /** 531 * Create a memory object from a winsys handle 532 * 533 * The underlying memory is most often allocated in by a foregin API. 534 * Then the underlying memory object is then exported through interfaces 535 * compatible with EXT_external_resources. 536 * 537 * Note: For WINSYS_HANDLE_TYPE_FD handles, the caller retains ownership 538 * of the fd. 539 * 540 * \param handle A handle representing the memory object to import 541 */ 542 struct pipe_memory_object *(*memobj_create_from_handle)(struct pipe_screen *screen, 543 struct winsys_handle *handle, 544 bool dedicated); 545 546 /** 547 * Destroy a memory object 548 * 549 * \param memobj The memory object to destroy 550 */ 551 void (*memobj_destroy)(struct pipe_screen *screen, 552 struct pipe_memory_object *memobj); 553 554 /** 555 * Create a texture from a memory object 556 * 557 * \param t texture template 558 * \param memobj The memory object used to back the texture 559 */ 560 struct pipe_resource * (*resource_from_memobj)(struct pipe_screen *screen, 561 const struct pipe_resource *t, 562 struct pipe_memory_object *memobj, 563 uint64_t offset); 564 565 /** 566 * Fill @uuid with a unique driver identifier 567 * 568 * \param uuid pointer to a memory region of PIPE_UUID_SIZE bytes 569 */ 570 void (*get_driver_uuid)(struct pipe_screen *screen, char *uuid); 571 572 /** 573 * Fill @uuid with a unique device identifier 574 * 575 * \param uuid pointer to a memory region of PIPE_UUID_SIZE bytes 576 */ 577 void (*get_device_uuid)(struct pipe_screen *screen, char *uuid); 578 579 /** 580 * Fill @luid with the locally unique identifier of the context 581 * The LUID returned, paired together with the contexts node mask, 582 * allows matching the context to an IDXGIAdapter1 object 583 * 584 * \param luid pointer to a memory region of PIPE_LUID_SIZE bytes 585 */ 586 void (*get_device_luid)(struct pipe_screen *screen, char *luid); 587 588 /** 589 * Return the device node mask identifying the context 590 * Together with the contexts LUID, this allows matching 591 * the context to an IDXGIAdapter1 object. 592 * 593 * within a linked device adapter 594 */ 595 uint32_t (*get_device_node_mask)(struct pipe_screen *screen); 596 597 /** 598 * Set the maximum number of parallel shader compiler threads. 599 */ 600 void (*set_max_shader_compiler_threads)(struct pipe_screen *screen, 601 unsigned max_threads); 602 603 /** 604 * Return whether parallel shader compilation has finished. 605 */ 606 bool (*is_parallel_shader_compilation_finished)(struct pipe_screen *screen, 607 void *shader, 608 enum pipe_shader_type shader_type); 609 610 void (*driver_thread_add_job)(struct pipe_screen *screen, 611 void *job, 612 struct util_queue_fence *fence, 613 pipe_driver_thread_func execute, 614 pipe_driver_thread_func cleanup, 615 const size_t job_size); 616 617 /** 618 * Set the damage region (called when KHR_partial_update() is invoked). 619 * This function is passed an array of rectangles encoding the damage area. 620 * rects are using the bottom-left origin convention. 621 * nrects = 0 means 'reset the damage region'. What 'reset' implies is HW 622 * specific. For tile-based renderers, the damage extent is typically set 623 * to cover the whole resource with no damage rect (or a 0-size damage 624 * rect). This way, the existing resource content is reloaded into the 625 * local tile buffer for every tile thus making partial tile update 626 * possible. For HW operating in immediate mode, this reset operation is 627 * likely to be a NOOP. 628 */ 629 void (*set_damage_region)(struct pipe_screen *screen, 630 struct pipe_resource *resource, 631 unsigned int nrects, 632 const struct pipe_box *rects); 633 634 /** 635 * Run driver-specific NIR lowering and optimization passes. 636 * 637 * gallium frontends should call this before passing shaders to drivers, 638 * and ideally also before shader caching. 639 * 640 * The driver may return a non-NULL string to trigger GLSL link failure 641 * and logging of that message in the GLSL linker log. 642 */ 643 char *(*finalize_nir)(struct pipe_screen *screen, void *nir); 644 645 /*Separated memory/resource allocations interfaces for Vulkan */ 646 647 /** 648 * Create a resource, and retrieve the required size for it but don't 649 * allocate any backing memory. 650 */ 651 struct pipe_resource * (*resource_create_unbacked)(struct pipe_screen *, 652 const struct pipe_resource *templat, 653 uint64_t *size_required); 654 655 /** 656 * Allocate backing memory to be bound to resources. 657 */ 658 struct pipe_memory_allocation *(*allocate_memory)(struct pipe_screen *screen, 659 uint64_t size); 660 /** 661 * Free previously allocated backing memory. 662 */ 663 void (*free_memory)(struct pipe_screen *screen, 664 struct pipe_memory_allocation *); 665 666 /** 667 * Allocate fd-based memory to be bound to resources. 668 */ 669 struct pipe_memory_allocation *(*allocate_memory_fd)(struct pipe_screen *screen, 670 uint64_t size, 671 int *fd, 672 bool dmabuf); 673 674 /** 675 * Import memory from an fd-handle. 676 */ 677 bool (*import_memory_fd)(struct pipe_screen *screen, 678 int fd, 679 struct pipe_memory_allocation **pmem, 680 uint64_t *size, 681 bool dmabuf); 682 683 /** 684 * Free previously allocated fd-based memory. 685 */ 686 void (*free_memory_fd)(struct pipe_screen *screen, 687 struct pipe_memory_allocation *pmem); 688 689 /** 690 * Bind memory to a resource. 691 */ 692 bool (*resource_bind_backing)(struct pipe_screen *screen, 693 struct pipe_resource *pt, 694 struct pipe_memory_allocation *pmem, 695 uint64_t fd_offset, 696 uint64_t size, 697 uint64_t offset); 698 699 /** 700 * Map backing memory. 701 */ 702 void *(*map_memory)(struct pipe_screen *screen, 703 struct pipe_memory_allocation *pmem); 704 705 /** 706 * Unmap backing memory. 707 */ 708 void (*unmap_memory)(struct pipe_screen *screen, 709 struct pipe_memory_allocation *pmem); 710 711 /** 712 * Determine whether the screen supports the specified modifier 713 * 714 * Query whether the driver supports a \p modifier in combination with 715 * \p format. If \p external_only is not NULL, the value it points to will 716 * be set to 0 or a non-zero value to indicate whether the modifier and 717 * format combination is supported only with external, or also with non- 718 * external texture targets respectively. The \p external_only parameter is 719 * not used when the function returns false. 720 * 721 * \return true if the format+modifier pair is supported on \p screen, false 722 * otherwise. 723 */ 724 bool (*is_dmabuf_modifier_supported)(struct pipe_screen *screen, 725 uint64_t modifier, enum pipe_format, 726 bool *external_only); 727 728 /** 729 * Get the number of planes required for a given modifier/format pair. 730 * 731 * If not NULL, this function returns the number of planes needed to 732 * represent \p format in the layout specified by \p modifier, including 733 * any driver-specific auxiliary data planes. 734 * 735 * Must only be called on a modifier supported by the screen for the 736 * specified format. 737 * 738 * If NULL, no auxiliary planes are required for any modifier+format pairs 739 * supported by \p screen. Hence, the plane count can be derived directly 740 * from \p format. 741 * 742 * \return Number of planes needed to store image data in the layout defined 743 * by \p format and \p modifier. 744 */ 745 unsigned int (*get_dmabuf_modifier_planes)(struct pipe_screen *screen, 746 uint64_t modifier, 747 enum pipe_format format); 748 749 /** 750 * Get supported page sizes for sparse texture. 751 * 752 * \p size is the array size of \p x, \p y and \p z. 753 * 754 * \p offset sets an offset into the possible format page size array, 755 * used to pick a specific xyz size combination. 756 * 757 * \return Number of supported page sizes, 0 means not support. 758 */ 759 int (*get_sparse_texture_virtual_page_size)(struct pipe_screen *screen, 760 enum pipe_texture_target target, 761 bool multi_sample, 762 enum pipe_format format, 763 unsigned offset, unsigned size, 764 int *x, int *y, int *z); 765 766 /** 767 * Vertex state CSO functions for precomputing vertex and index buffer 768 * states for display lists. 769 */ 770 pipe_create_vertex_state_func create_vertex_state; 771 pipe_vertex_state_destroy_func vertex_state_destroy; 772 773 /** 774 * Update a timeline semaphore value stored within a driver fence object. 775 * Future waits and signals will use the new value. 776 */ 777 void (*set_fence_timeline_value)(struct pipe_screen *screen, 778 struct pipe_fence_handle *fence, 779 uint64_t value); 780 781 /** 782 * Get additional data for interop_query_device_info 783 * 784 * \p in_data_size is how much data was allocated by the caller 785 * \p data is the buffer to fill 786 * 787 * \return how much data was written 788 */ 789 uint32_t (*interop_query_device_info)(struct pipe_screen *screen, 790 uint32_t in_data_size, 791 void *data); 792 793 /** 794 * Get additional data for interop_export_object 795 * 796 * \p in_data_size is how much data was allocated by the caller 797 * \p data is the buffer to fill 798 * \p need_export_dmabuf can be set to false to prevent 799 * a following call to resource_get_handle, if the private 800 * data contains the exported data 801 * 802 * \return how much data was written 803 */ 804 uint32_t (*interop_export_object)(struct pipe_screen *screen, 805 struct pipe_resource *res, 806 uint32_t in_data_size, 807 void *data, 808 bool *need_export_dmabuf); 809 810 /** 811 * Get supported compression fixed rates (bits per component) for a format. 812 * If \p max is 0, the total number of supported rates for the supplied 813 * format is returned in \p count, with no modification to \p rates. 814 * Otherwise, \p rates is filled with upto \p max supported compression 815 * rates, and \p count with the number of values copied. 816 */ 817 void (*query_compression_rates)(struct pipe_screen *screen, 818 enum pipe_format format, int max, 819 uint32_t *rates, int *count); 820 821 /** 822 * Get modifiers associated with a given compression fixed rate. 823 * If \p rate is PIPE_COMPRESSION_FIXED_RATE_DEFAULT, supported compression 824 * modifiers are returned in order of priority. 825 * If \p max is 0, the total number of supported modifiers for the supplied 826 * compression rate is returned in \p count, with no modification to \p 827 * modifiers. Otherwise, \p modifiers is filled with upto \p max supported 828 * modifiers, and \p count with the number of values copied. 829 */ 830 void (*query_compression_modifiers)(struct pipe_screen *screen, 831 enum pipe_format format, uint32_t rate, 832 int max, uint64_t *modifiers, int *count); 833 834 /** 835 * Determine whether the modifer is enabling fixed-rate compression for 836 * the given screen and format. 837 * 838 * If \p rate is not NULL, the value it points to will be set to the 839 * bitrate (bits per component) associated with the modifier. 840 * 841 * \return true if the format+modifier pair is enabling fixed-rate 842 * compression on \p screen, false otherwise. 843 */ 844 bool (*is_compression_modifier)(struct pipe_screen *screen, 845 enum pipe_format format, uint64_t modifier, 846 uint32_t *rate); 847 848 /** 849 * Check if the given \p target buffer is supported as output (or input for 850 * encode) for this \p profile and \p entrypoint. 851 * 852 * If \p format is different from target->buffer_format this function 853 * checks if the \p target buffer can be converted to \p format as part 854 * of the given operation (eg. encoder accepts RGB input and converts 855 * it to YUV). 856 * 857 * \return true if the buffer is supported for given operation, false 858 * otherwise. 859 */ 860 bool (*is_video_target_buffer_supported)(struct pipe_screen *screen, 861 enum pipe_format format, 862 struct pipe_video_buffer *target, 863 enum pipe_video_profile profile, 864 enum pipe_video_entrypoint entrypoint); 865 866 /** 867 * pipe_screen is inherited by driver's screen but a simple cast to convert 868 * from the generic interface to the driver version won't work if dd_pipe 869 * is used. 870 */ 871 struct pipe_screen* (*get_driver_pipe_screen)(struct pipe_screen *screen); 872 }; 873 874 875 /** 876 * Global configuration options for screen creation. 877 */ 878 struct pipe_screen_config { 879 bool driver_name_is_inferred; 880 struct driOptionCache *options; 881 const struct driOptionCache *options_info; 882 }; 883 884 885 #ifdef __cplusplus 886 } 887 #endif 888 889 #endif /* P_SCREEN_H */ 890