14a49301eSmrg/************************************************************************** 24a49301eSmrg * 3af69d88dSmrg * Copyright 2007 VMware, Inc. 44a49301eSmrg * All Rights Reserved. 54a49301eSmrg * 64a49301eSmrg * Permission is hereby granted, free of charge, to any person obtaining a 74a49301eSmrg * copy of this software and associated documentation files (the 84a49301eSmrg * "Software"), to deal in the Software without restriction, including 94a49301eSmrg * without limitation the rights to use, copy, modify, merge, publish, 104a49301eSmrg * distribute, sub license, and/or sell copies of the Software, and to 114a49301eSmrg * permit persons to whom the Software is furnished to do so, subject to 124a49301eSmrg * the following conditions: 134a49301eSmrg * 144a49301eSmrg * The above copyright notice and this permission notice (including the 154a49301eSmrg * next paragraph) shall be included in all copies or substantial portions 164a49301eSmrg * of the Software. 174a49301eSmrg * 184a49301eSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 194a49301eSmrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 204a49301eSmrg * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 21af69d88dSmrg * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR 224a49301eSmrg * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 234a49301eSmrg * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 244a49301eSmrg * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 254a49301eSmrg * 264a49301eSmrg **************************************************************************/ 274a49301eSmrg 284a49301eSmrg/** 294a49301eSmrg * @file 304a49301eSmrg * 314a49301eSmrg * Screen, Adapter or GPU 324a49301eSmrg * 334a49301eSmrg * These are driver functions/facilities that are context independent. 344a49301eSmrg */ 354a49301eSmrg 364a49301eSmrg 374a49301eSmrg#ifndef P_SCREEN_H 384a49301eSmrg#define P_SCREEN_H 394a49301eSmrg 404a49301eSmrg 414a49301eSmrg#include "pipe/p_compiler.h" 424a49301eSmrg#include "pipe/p_format.h" 434a49301eSmrg#include "pipe/p_defines.h" 44af69d88dSmrg#include "pipe/p_video_enums.h" 454a49301eSmrg 464a49301eSmrg 474a49301eSmrg 484a49301eSmrg#ifdef __cplusplus 494a49301eSmrgextern "C" { 504a49301eSmrg#endif 514a49301eSmrg 524a49301eSmrg 53af69d88dSmrg/** Opaque types */ 543464ebd5Sriastradhstruct winsys_handle; 554a49301eSmrgstruct pipe_fence_handle; 563464ebd5Sriastradhstruct pipe_resource; 574a49301eSmrgstruct pipe_surface; 584a49301eSmrgstruct pipe_transfer; 59af69d88dSmrgstruct pipe_box; 6001e04c3fSmrgstruct pipe_memory_info; 617ec681f3Smrgstruct pipe_vertex_buffer; 627ec681f3Smrgstruct pipe_vertex_element; 637ec681f3Smrgstruct pipe_vertex_state; 6401e04c3fSmrgstruct disk_cache; 6501e04c3fSmrgstruct driOptionCache; 6601e04c3fSmrgstruct u_transfer_helper; 677ec681f3Smrgstruct pipe_screen; 687ec681f3Smrg 697ec681f3Smrgtypedef struct pipe_vertex_state * 707ec681f3Smrg (*pipe_create_vertex_state_func)(struct pipe_screen *screen, 717ec681f3Smrg struct pipe_vertex_buffer *buffer, 727ec681f3Smrg const struct pipe_vertex_element *elements, 737ec681f3Smrg unsigned num_elements, 747ec681f3Smrg struct pipe_resource *indexbuf, 757ec681f3Smrg uint32_t full_velem_mask); 767ec681f3Smrgtypedef void (*pipe_vertex_state_destroy_func)(struct pipe_screen *screen, 777ec681f3Smrg struct pipe_vertex_state *); 784a49301eSmrg 794a49301eSmrg/** 804a49301eSmrg * Gallium screen/adapter context. Basically everything 814a49301eSmrg * hardware-specific that doesn't actually require a rendering 824a49301eSmrg * context. 834a49301eSmrg */ 844a49301eSmrgstruct pipe_screen { 857ec681f3Smrg /** 867ec681f3Smrg * Atomically incremented by drivers to track the number of contexts. 877ec681f3Smrg * If it's 0, it can be assumed that contexts are not tracked. 887ec681f3Smrg * Used by some places to skip locking if num_contexts == 1. 897ec681f3Smrg */ 907ec681f3Smrg unsigned num_contexts; 9101e04c3fSmrg 9201e04c3fSmrg /** 9301e04c3fSmrg * For drivers using u_transfer_helper: 9401e04c3fSmrg */ 9501e04c3fSmrg struct u_transfer_helper *transfer_helper; 9601e04c3fSmrg 974a49301eSmrg void (*destroy)( struct pipe_screen * ); 984a49301eSmrg 994a49301eSmrg const char *(*get_name)( struct pipe_screen * ); 1004a49301eSmrg 1014a49301eSmrg const char *(*get_vendor)( struct pipe_screen * ); 1024a49301eSmrg 10301e04c3fSmrg /** 10401e04c3fSmrg * Returns the device vendor. 10501e04c3fSmrg * 10601e04c3fSmrg * The returned value should return the actual device vendor/manufacturer, 10701e04c3fSmrg * rather than a potentially generic driver string. 10801e04c3fSmrg */ 10901e04c3fSmrg const char *(*get_device_vendor)( struct pipe_screen * ); 11001e04c3fSmrg 1114a49301eSmrg /** 1124a49301eSmrg * Query an integer-valued capability/parameter/limit 1134a49301eSmrg * \param param one of PIPE_CAP_x 1144a49301eSmrg */ 1153464ebd5Sriastradh int (*get_param)( struct pipe_screen *, enum pipe_cap param ); 1164a49301eSmrg 1174a49301eSmrg /** 1184a49301eSmrg * Query a float-valued capability/parameter/limit 1194a49301eSmrg * \param param one of PIPE_CAP_x 1204a49301eSmrg */ 121af69d88dSmrg float (*get_paramf)( struct pipe_screen *, enum pipe_capf param ); 1223464ebd5Sriastradh 1233464ebd5Sriastradh /** 1243464ebd5Sriastradh * Query a per-shader-stage integer-valued capability/parameter/limit 1253464ebd5Sriastradh * \param param one of PIPE_CAP_x 1263464ebd5Sriastradh */ 12701e04c3fSmrg int (*get_shader_param)( struct pipe_screen *, enum pipe_shader_type shader, 12801e04c3fSmrg enum pipe_shader_cap param ); 1294a49301eSmrg 130af69d88dSmrg /** 131af69d88dSmrg * Query an integer-valued capability/parameter/limit for a codec/profile 132af69d88dSmrg * \param param one of PIPE_VIDEO_CAP_x 133af69d88dSmrg */ 134af69d88dSmrg int (*get_video_param)( struct pipe_screen *, 135af69d88dSmrg enum pipe_video_profile profile, 136af69d88dSmrg enum pipe_video_entrypoint entrypoint, 137af69d88dSmrg enum pipe_video_cap param ); 138af69d88dSmrg 139af69d88dSmrg /** 140af69d88dSmrg * Query a compute-specific capability/parameter/limit. 14101e04c3fSmrg * \param ir_type shader IR type for which the param applies, or don't care 14201e04c3fSmrg * if the param is not shader related 14301e04c3fSmrg * \param param one of PIPE_COMPUTE_CAP_x 14401e04c3fSmrg * \param ret pointer to a preallocated buffer that will be 14501e04c3fSmrg * initialized to the parameter value, or NULL. 14601e04c3fSmrg * \return size in bytes of the parameter value that would be 14701e04c3fSmrg * returned. 148af69d88dSmrg */ 149af69d88dSmrg int (*get_compute_param)(struct pipe_screen *, 15001e04c3fSmrg enum pipe_shader_ir ir_type, 151af69d88dSmrg enum pipe_compute_cap param, 152af69d88dSmrg void *ret); 153af69d88dSmrg 15401e04c3fSmrg /** 15501e04c3fSmrg * Get the sample pixel grid's size. This function requires 15601e04c3fSmrg * PIPE_CAP_PROGRAMMABLE_SAMPLE_LOCATIONS to be callable. 15701e04c3fSmrg * 15801e04c3fSmrg * \param sample_count - total number of samples 15901e04c3fSmrg * \param out_width - the width of the pixel grid 16001e04c3fSmrg * \param out_height - the height of the pixel grid 16101e04c3fSmrg */ 16201e04c3fSmrg void (*get_sample_pixel_grid)(struct pipe_screen *, unsigned sample_count, 16301e04c3fSmrg unsigned *out_width, unsigned *out_height); 16401e04c3fSmrg 165af69d88dSmrg /** 166af69d88dSmrg * Query a timestamp in nanoseconds. The returned value should match 167af69d88dSmrg * PIPE_QUERY_TIMESTAMP. This function returns immediately and doesn't 168af69d88dSmrg * wait for rendering to complete (which cannot be achieved with queries). 169af69d88dSmrg */ 170af69d88dSmrg uint64_t (*get_timestamp)(struct pipe_screen *); 171af69d88dSmrg 17201e04c3fSmrg /** 17301e04c3fSmrg * Create a context. 17401e04c3fSmrg * 17501e04c3fSmrg * \param screen pipe screen 17601e04c3fSmrg * \param priv a pointer to set in pipe_context::priv 17701e04c3fSmrg * \param flags a mask of PIPE_CONTEXT_* flags 17801e04c3fSmrg */ 17901e04c3fSmrg struct pipe_context * (*context_create)(struct pipe_screen *screen, 18001e04c3fSmrg void *priv, unsigned flags); 1813464ebd5Sriastradh 1824a49301eSmrg /** 1834a49301eSmrg * Check if the given pipe_format is supported as a texture or 1844a49301eSmrg * drawing surface. 1853464ebd5Sriastradh * \param bindings bitmask of PIPE_BIND_* 1864a49301eSmrg */ 1877ec681f3Smrg bool (*is_format_supported)( struct pipe_screen *, 1887ec681f3Smrg enum pipe_format format, 1897ec681f3Smrg enum pipe_texture_target target, 1907ec681f3Smrg unsigned sample_count, 1917ec681f3Smrg unsigned storage_sample_count, 1927ec681f3Smrg unsigned bindings ); 1934a49301eSmrg 194af69d88dSmrg /** 195af69d88dSmrg * Check if the given pipe_format is supported as output for this codec/profile. 196af69d88dSmrg * \param profile profile to check, may also be PIPE_VIDEO_PROFILE_UNKNOWN 197af69d88dSmrg */ 1987ec681f3Smrg bool (*is_video_format_supported)( struct pipe_screen *, 1997ec681f3Smrg enum pipe_format format, 2007ec681f3Smrg enum pipe_video_profile profile, 2017ec681f3Smrg enum pipe_video_entrypoint entrypoint ); 202af69d88dSmrg 203af69d88dSmrg /** 204af69d88dSmrg * Check if we can actually create the given resource (test the dimension, 205af69d88dSmrg * overall size, etc). Used to implement proxy textures. 206af69d88dSmrg * \return TRUE if size is OK, FALSE if too large. 207af69d88dSmrg */ 2087ec681f3Smrg bool (*can_create_resource)(struct pipe_screen *screen, 2097ec681f3Smrg const struct pipe_resource *templat); 21001e04c3fSmrg 2114a49301eSmrg /** 2124a49301eSmrg * Create a new texture object, using the given template info. 2134a49301eSmrg */ 2143464ebd5Sriastradh struct pipe_resource * (*resource_create)(struct pipe_screen *, 2153464ebd5Sriastradh const struct pipe_resource *templat); 2164a49301eSmrg 21701e04c3fSmrg struct pipe_resource * (*resource_create_front)(struct pipe_screen *, 21801e04c3fSmrg const struct pipe_resource *templat, 21901e04c3fSmrg const void *map_front_private); 22001e04c3fSmrg 2214a49301eSmrg /** 2223464ebd5Sriastradh * Create a texture from a winsys_handle. The handle is often created in 2233464ebd5Sriastradh * another process by first creating a pipe texture and then calling 2243464ebd5Sriastradh * resource_get_handle. 22501e04c3fSmrg * 22601e04c3fSmrg * NOTE: in the case of WINSYS_HANDLE_TYPE_FD handles, the caller 22701e04c3fSmrg * retains ownership of the FD. (This is consistent with 22801e04c3fSmrg * EGL_EXT_image_dma_buf_import) 22901e04c3fSmrg * 23001e04c3fSmrg * \param usage A combination of PIPE_HANDLE_USAGE_* flags. 2314a49301eSmrg */ 2323464ebd5Sriastradh struct pipe_resource * (*resource_from_handle)(struct pipe_screen *, 2333464ebd5Sriastradh const struct pipe_resource *templat, 23401e04c3fSmrg struct winsys_handle *handle, 23501e04c3fSmrg unsigned usage); 23601e04c3fSmrg 23701e04c3fSmrg /** 23801e04c3fSmrg * Create a resource from user memory. This maps the user memory into 23901e04c3fSmrg * the device address space. 24001e04c3fSmrg */ 24101e04c3fSmrg struct pipe_resource * (*resource_from_user_memory)(struct pipe_screen *, 24201e04c3fSmrg const struct pipe_resource *t, 24301e04c3fSmrg void *user_memory); 24401e04c3fSmrg 24501e04c3fSmrg /** 2467ec681f3Smrg * Unlike pipe_resource::bind, which describes what gallium frontends want, 24701e04c3fSmrg * resources can have much greater capabilities in practice, often implied 24801e04c3fSmrg * by the tiling layout or memory placement. This function allows querying 24901e04c3fSmrg * whether a capability is supported beyond what was requested by state 25001e04c3fSmrg * trackers. It's also useful for querying capabilities of imported 25101e04c3fSmrg * resources where the capabilities are unknown at first. 25201e04c3fSmrg * 25301e04c3fSmrg * Only these flags are allowed: 25401e04c3fSmrg * - PIPE_BIND_SCANOUT 25501e04c3fSmrg * - PIPE_BIND_CURSOR 25601e04c3fSmrg * - PIPE_BIND_LINEAR 25701e04c3fSmrg */ 25801e04c3fSmrg bool (*check_resource_capability)(struct pipe_screen *screen, 25901e04c3fSmrg struct pipe_resource *resource, 26001e04c3fSmrg unsigned bind); 2614a49301eSmrg 2623464ebd5Sriastradh /** 2633464ebd5Sriastradh * Get a winsys_handle from a texture. Some platforms/winsys requires 2643464ebd5Sriastradh * that the texture is created with a special usage flag like 2653464ebd5Sriastradh * DISPLAYTARGET or PRIMARY. 26601e04c3fSmrg * 26701e04c3fSmrg * The context parameter can optionally be used to flush the resource and 26801e04c3fSmrg * the context to make sure the resource is coherent with whatever user 26901e04c3fSmrg * will use it. Some drivers may also use the context to convert 27001e04c3fSmrg * the resource into a format compatible for sharing. The use case is 27101e04c3fSmrg * OpenGL-OpenCL interop. The context parameter is allowed to be NULL. 27201e04c3fSmrg * 2737ec681f3Smrg * NOTE: for multi-planar resources (which may or may not have the planes 2747ec681f3Smrg * chained through the pipe_resource next pointer) the frontend will 2757ec681f3Smrg * always call this function with the first resource of the chain. It is 2767ec681f3Smrg * the pipe drivers responsibility to walk the resources as needed when 2777ec681f3Smrg * called with handle->plane != 0. 2787ec681f3Smrg * 27901e04c3fSmrg * NOTE: in the case of WINSYS_HANDLE_TYPE_FD handles, the caller 28001e04c3fSmrg * takes ownership of the FD. (This is consistent with 28101e04c3fSmrg * EGL_MESA_image_dma_buf_export) 28201e04c3fSmrg * 28301e04c3fSmrg * \param usage A combination of PIPE_HANDLE_USAGE_* flags. 284cdc920a0Smrg */ 2857ec681f3Smrg bool (*resource_get_handle)(struct pipe_screen *, 2867ec681f3Smrg struct pipe_context *context, 2877ec681f3Smrg struct pipe_resource *tex, 2887ec681f3Smrg struct winsys_handle *handle, 2897ec681f3Smrg unsigned usage); 2907ec681f3Smrg 2917ec681f3Smrg /** 2927ec681f3Smrg * Get info for the given pipe resource without the need to get a 2937ec681f3Smrg * winsys_handle. 2947ec681f3Smrg * 2957ec681f3Smrg * The context parameter can optionally be used to flush the resource and 2967ec681f3Smrg * the context to make sure the resource is coherent with whatever user 2977ec681f3Smrg * will use it. Some drivers may also use the context to convert 2987ec681f3Smrg * the resource into a format compatible for sharing. The context parameter 2997ec681f3Smrg * is allowed to be NULL. 3007ec681f3Smrg */ 3017ec681f3Smrg bool (*resource_get_param)(struct pipe_screen *screen, 3027ec681f3Smrg struct pipe_context *context, 3037ec681f3Smrg struct pipe_resource *resource, 3047ec681f3Smrg unsigned plane, 3057ec681f3Smrg unsigned layer, 3067ec681f3Smrg unsigned level, 3077ec681f3Smrg enum pipe_resource_param param, 3087ec681f3Smrg unsigned handle_usage, 3097ec681f3Smrg uint64_t *value); 3104a49301eSmrg 3119f464c52Smaya /** 3129f464c52Smaya * Get stride and offset for the given pipe resource without the need to get 3139f464c52Smaya * a winsys_handle. 3149f464c52Smaya */ 3159f464c52Smaya void (*resource_get_info)(struct pipe_screen *screen, 3169f464c52Smaya struct pipe_resource *resource, 3179f464c52Smaya unsigned *stride, 3189f464c52Smaya unsigned *offset); 3199f464c52Smaya 32001e04c3fSmrg /** 32101e04c3fSmrg * Mark the resource as changed so derived internal resources will be 32201e04c3fSmrg * recreated on next use. 32301e04c3fSmrg * 32401e04c3fSmrg * This is necessary when reimporting external images that can't be directly 32501e04c3fSmrg * used as texture sampler source, to avoid sampling from old copies. 32601e04c3fSmrg */ 32701e04c3fSmrg void (*resource_changed)(struct pipe_screen *, struct pipe_resource *pt); 3284a49301eSmrg 3293464ebd5Sriastradh void (*resource_destroy)(struct pipe_screen *, 3303464ebd5Sriastradh struct pipe_resource *pt); 3314a49301eSmrg 3324a49301eSmrg 3334a49301eSmrg /** 3344a49301eSmrg * Do any special operations to ensure frontbuffer contents are 3354a49301eSmrg * displayed, eg copy fake frontbuffer. 3363464ebd5Sriastradh * \param winsys_drawable_handle an opaque handle that the calling context 3373464ebd5Sriastradh * gets out-of-band 338af69d88dSmrg * \param subbox an optional sub region to flush 3394a49301eSmrg */ 3404a49301eSmrg void (*flush_frontbuffer)( struct pipe_screen *screen, 3417ec681f3Smrg struct pipe_context *ctx, 3423464ebd5Sriastradh struct pipe_resource *resource, 3433464ebd5Sriastradh unsigned level, unsigned layer, 344af69d88dSmrg void *winsys_drawable_handle, 345af69d88dSmrg struct pipe_box *subbox ); 3464a49301eSmrg 3474a49301eSmrg /** Set ptr = fence, with reference counting */ 3484a49301eSmrg void (*fence_reference)( struct pipe_screen *screen, 3494a49301eSmrg struct pipe_fence_handle **ptr, 3504a49301eSmrg struct pipe_fence_handle *fence ); 3514a49301eSmrg 3524a49301eSmrg /** 35301e04c3fSmrg * Wait for the fence to finish. 35401e04c3fSmrg * 35501e04c3fSmrg * If the fence was created with PIPE_FLUSH_DEFERRED, and the context is 35601e04c3fSmrg * still unflushed, and the ctx parameter of fence_finish is equal to 35701e04c3fSmrg * the context where the fence was created, fence_finish will flush 35801e04c3fSmrg * the context prior to waiting for the fence. 35901e04c3fSmrg * 36001e04c3fSmrg * In all other cases, the ctx parameter has no effect. 36101e04c3fSmrg * 36201e04c3fSmrg * \param timeout in nanoseconds (may be PIPE_TIMEOUT_INFINITE). 3634a49301eSmrg */ 3647ec681f3Smrg bool (*fence_finish)(struct pipe_screen *screen, 3657ec681f3Smrg struct pipe_context *ctx, 3667ec681f3Smrg struct pipe_fence_handle *fence, 3677ec681f3Smrg uint64_t timeout); 3684a49301eSmrg 3694a49301eSmrg /** 37001e04c3fSmrg * For fences created with PIPE_FLUSH_FENCE_FD (exported fd) or 37101e04c3fSmrg * by create_fence_fd() (imported fd), return the native fence fd 37201e04c3fSmrg * associated with the fence. This may return -1 for fences 37301e04c3fSmrg * created with PIPE_FLUSH_DEFERRED if the fence command has not 37401e04c3fSmrg * been flushed yet. 3754a49301eSmrg */ 37601e04c3fSmrg int (*fence_get_fd)(struct pipe_screen *screen, 37701e04c3fSmrg struct pipe_fence_handle *fence); 3784a49301eSmrg 379af69d88dSmrg /** 380af69d88dSmrg * Returns a driver-specific query. 381af69d88dSmrg * 382af69d88dSmrg * If \p info is NULL, the number of available queries is returned. 383af69d88dSmrg * Otherwise, the driver query at the specified \p index is returned 384af69d88dSmrg * in \p info. The function returns non-zero on success. 385af69d88dSmrg */ 386af69d88dSmrg int (*get_driver_query_info)(struct pipe_screen *screen, 387af69d88dSmrg unsigned index, 388af69d88dSmrg struct pipe_driver_query_info *info); 389af69d88dSmrg 39001e04c3fSmrg /** 39101e04c3fSmrg * Returns a driver-specific query group. 39201e04c3fSmrg * 39301e04c3fSmrg * If \p info is NULL, the number of available groups is returned. 39401e04c3fSmrg * Otherwise, the driver query group at the specified \p index is returned 39501e04c3fSmrg * in \p info. The function returns non-zero on success. 39601e04c3fSmrg */ 39701e04c3fSmrg int (*get_driver_query_group_info)(struct pipe_screen *screen, 39801e04c3fSmrg unsigned index, 39901e04c3fSmrg struct pipe_driver_query_group_info *info); 40001e04c3fSmrg 40101e04c3fSmrg /** 40201e04c3fSmrg * Query information about memory usage. 40301e04c3fSmrg */ 40401e04c3fSmrg void (*query_memory_info)(struct pipe_screen *screen, 40501e04c3fSmrg struct pipe_memory_info *info); 40601e04c3fSmrg 40701e04c3fSmrg /** 40801e04c3fSmrg * Get IR specific compiler options struct. For PIPE_SHADER_IR_NIR this 40901e04c3fSmrg * returns a 'struct nir_shader_compiler_options'. Drivers reporting 41001e04c3fSmrg * NIR as the preferred IR must implement this. 41101e04c3fSmrg */ 41201e04c3fSmrg const void *(*get_compiler_options)(struct pipe_screen *screen, 41301e04c3fSmrg enum pipe_shader_ir ir, 41401e04c3fSmrg enum pipe_shader_type shader); 41501e04c3fSmrg 41601e04c3fSmrg /** 41701e04c3fSmrg * Returns a pointer to a driver-specific on-disk shader cache. If the 41801e04c3fSmrg * driver failed to create the cache or does not support an on-disk shader 41901e04c3fSmrg * cache NULL is returned. The callback itself may also be NULL if the 42001e04c3fSmrg * driver doesn't support an on-disk shader cache. 42101e04c3fSmrg */ 42201e04c3fSmrg struct disk_cache *(*get_disk_shader_cache)(struct pipe_screen *screen); 42301e04c3fSmrg 42401e04c3fSmrg /** 42501e04c3fSmrg * Create a new texture object from the given template info, taking 42601e04c3fSmrg * format modifiers into account. \p modifiers specifies a list of format 42701e04c3fSmrg * modifier tokens, as defined in drm_fourcc.h. The driver then picks the 42801e04c3fSmrg * best modifier among these and creates the resource. \p count must 42901e04c3fSmrg * contain the size of \p modifiers array. 43001e04c3fSmrg * 43101e04c3fSmrg * Returns NULL if an entry in \p modifiers is unsupported by the driver, 43201e04c3fSmrg * or if only DRM_FORMAT_MOD_INVALID is provided. 43301e04c3fSmrg */ 43401e04c3fSmrg struct pipe_resource * (*resource_create_with_modifiers)( 43501e04c3fSmrg struct pipe_screen *, 43601e04c3fSmrg const struct pipe_resource *templat, 43701e04c3fSmrg const uint64_t *modifiers, int count); 43801e04c3fSmrg 43901e04c3fSmrg /** 44001e04c3fSmrg * Get supported modifiers for a format. 44101e04c3fSmrg * If \p max is 0, the total number of supported modifiers for the supplied 44201e04c3fSmrg * format is returned in \p count, with no modification to \p modifiers. 44301e04c3fSmrg * Otherwise, \p modifiers is filled with upto \p max supported modifier 44401e04c3fSmrg * codes, and \p count with the number of modifiers copied. 44501e04c3fSmrg * The \p external_only array is used to return whether the format and 44601e04c3fSmrg * modifier combination can only be used with an external texture target. 44701e04c3fSmrg */ 44801e04c3fSmrg void (*query_dmabuf_modifiers)(struct pipe_screen *screen, 44901e04c3fSmrg enum pipe_format format, int max, 45001e04c3fSmrg uint64_t *modifiers, 45101e04c3fSmrg unsigned int *external_only, int *count); 45201e04c3fSmrg 45301e04c3fSmrg /** 45401e04c3fSmrg * Create a memory object from a winsys handle 45501e04c3fSmrg * 45601e04c3fSmrg * The underlying memory is most often allocated in by a foregin API. 45701e04c3fSmrg * Then the underlying memory object is then exported through interfaces 45801e04c3fSmrg * compatible with EXT_external_resources. 45901e04c3fSmrg * 46001e04c3fSmrg * Note: For WINSYS_HANDLE_TYPE_FD handles, the caller retains ownership 46101e04c3fSmrg * of the fd. 46201e04c3fSmrg * 46301e04c3fSmrg * \param handle A handle representing the memory object to import 46401e04c3fSmrg */ 46501e04c3fSmrg struct pipe_memory_object *(*memobj_create_from_handle)(struct pipe_screen *screen, 46601e04c3fSmrg struct winsys_handle *handle, 46701e04c3fSmrg bool dedicated); 46801e04c3fSmrg 46901e04c3fSmrg /** 47001e04c3fSmrg * Destroy a memory object 47101e04c3fSmrg * 47201e04c3fSmrg * \param memobj The memory object to destroy 47301e04c3fSmrg */ 47401e04c3fSmrg void (*memobj_destroy)(struct pipe_screen *screen, 47501e04c3fSmrg struct pipe_memory_object *memobj); 47601e04c3fSmrg 47701e04c3fSmrg /** 47801e04c3fSmrg * Create a texture from a memory object 47901e04c3fSmrg * 48001e04c3fSmrg * \param t texture template 48101e04c3fSmrg * \param memobj The memory object used to back the texture 48201e04c3fSmrg */ 48301e04c3fSmrg struct pipe_resource * (*resource_from_memobj)(struct pipe_screen *screen, 48401e04c3fSmrg const struct pipe_resource *t, 48501e04c3fSmrg struct pipe_memory_object *memobj, 48601e04c3fSmrg uint64_t offset); 48701e04c3fSmrg 48801e04c3fSmrg /** 48901e04c3fSmrg * Fill @uuid with a unique driver identifier 49001e04c3fSmrg * 49101e04c3fSmrg * \param uuid pointer to a memory region of PIPE_UUID_SIZE bytes 49201e04c3fSmrg */ 49301e04c3fSmrg void (*get_driver_uuid)(struct pipe_screen *screen, char *uuid); 49401e04c3fSmrg 49501e04c3fSmrg /** 49601e04c3fSmrg * Fill @uuid with a unique device identifier 49701e04c3fSmrg * 49801e04c3fSmrg * \param uuid pointer to a memory region of PIPE_UUID_SIZE bytes 49901e04c3fSmrg */ 50001e04c3fSmrg void (*get_device_uuid)(struct pipe_screen *screen, char *uuid); 5019f464c52Smaya 5029f464c52Smaya /** 5039f464c52Smaya * Set the maximum number of parallel shader compiler threads. 5049f464c52Smaya */ 5059f464c52Smaya void (*set_max_shader_compiler_threads)(struct pipe_screen *screen, 5069f464c52Smaya unsigned max_threads); 5079f464c52Smaya 5089f464c52Smaya /** 5099f464c52Smaya * Return whether parallel shader compilation has finished. 5109f464c52Smaya */ 5119f464c52Smaya bool (*is_parallel_shader_compilation_finished)(struct pipe_screen *screen, 5129f464c52Smaya void *shader, 5139f464c52Smaya unsigned shader_type); 5147ec681f3Smrg 5157ec681f3Smrg /** 5167ec681f3Smrg * Set the damage region (called when KHR_partial_update() is invoked). 5177ec681f3Smrg * This function is passed an array of rectangles encoding the damage area. 5187ec681f3Smrg * rects are using the bottom-left origin convention. 5197ec681f3Smrg * nrects = 0 means 'reset the damage region'. What 'reset' implies is HW 5207ec681f3Smrg * specific. For tile-based renderers, the damage extent is typically set 5217ec681f3Smrg * to cover the whole resource with no damage rect (or a 0-size damage 5227ec681f3Smrg * rect). This way, the existing resource content is reloaded into the 5237ec681f3Smrg * local tile buffer for every tile thus making partial tile update 5247ec681f3Smrg * possible. For HW operating in immediate mode, this reset operation is 5257ec681f3Smrg * likely to be a NOOP. 5267ec681f3Smrg */ 5277ec681f3Smrg void (*set_damage_region)(struct pipe_screen *screen, 5287ec681f3Smrg struct pipe_resource *resource, 5297ec681f3Smrg unsigned int nrects, 5307ec681f3Smrg const struct pipe_box *rects); 5317ec681f3Smrg 5327ec681f3Smrg /** 5337ec681f3Smrg * Run driver-specific NIR lowering and optimization passes. 5347ec681f3Smrg * 5357ec681f3Smrg * gallium frontends should call this before passing shaders to drivers, 5367ec681f3Smrg * and ideally also before shader caching. 5377ec681f3Smrg * 5387ec681f3Smrg * The driver may return a non-NULL string to trigger GLSL link failure and 5397ec681f3Smrg * logging of that message in the GLSL linker log. 5407ec681f3Smrg */ 5417ec681f3Smrg char *(*finalize_nir)(struct pipe_screen *screen, void *nir); 5427ec681f3Smrg 5437ec681f3Smrg /*Separated memory/resource allocations interfaces for Vulkan */ 5447ec681f3Smrg 5457ec681f3Smrg /** 5467ec681f3Smrg * Create a resource, and retrieve the required size for it but don't allocate 5477ec681f3Smrg * any backing memory. 5487ec681f3Smrg */ 5497ec681f3Smrg struct pipe_resource * (*resource_create_unbacked)(struct pipe_screen *, 5507ec681f3Smrg const struct pipe_resource *templat, 5517ec681f3Smrg uint64_t *size_required); 5527ec681f3Smrg 5537ec681f3Smrg /** 5547ec681f3Smrg * Allocate backing memory to be bound to resources. 5557ec681f3Smrg */ 5567ec681f3Smrg struct pipe_memory_allocation *(*allocate_memory)(struct pipe_screen *screen, 5577ec681f3Smrg uint64_t size); 5587ec681f3Smrg /** 5597ec681f3Smrg * Free previously allocated backing memory. 5607ec681f3Smrg */ 5617ec681f3Smrg void (*free_memory)(struct pipe_screen *screen, 5627ec681f3Smrg struct pipe_memory_allocation *); 5637ec681f3Smrg 5647ec681f3Smrg /** 5657ec681f3Smrg * Allocate fd-based memory to be bound to resources. 5667ec681f3Smrg */ 5677ec681f3Smrg struct pipe_memory_allocation *(*allocate_memory_fd)(struct pipe_screen *screen, 5687ec681f3Smrg uint64_t size, 5697ec681f3Smrg int *fd); 5707ec681f3Smrg 5717ec681f3Smrg /** 5727ec681f3Smrg * Import memory from an fd-handle. 5737ec681f3Smrg */ 5747ec681f3Smrg bool (*import_memory_fd)(struct pipe_screen *screen, 5757ec681f3Smrg int fd, 5767ec681f3Smrg struct pipe_memory_allocation **pmem, 5777ec681f3Smrg uint64_t *size); 5787ec681f3Smrg 5797ec681f3Smrg /** 5807ec681f3Smrg * Free previously allocated fd-based memory. 5817ec681f3Smrg */ 5827ec681f3Smrg void (*free_memory_fd)(struct pipe_screen *screen, 5837ec681f3Smrg struct pipe_memory_allocation *pmem); 5847ec681f3Smrg 5857ec681f3Smrg /** 5867ec681f3Smrg * Bind memory to a resource. 5877ec681f3Smrg */ 5887ec681f3Smrg bool (*resource_bind_backing)(struct pipe_screen *screen, 5897ec681f3Smrg struct pipe_resource *pt, 5907ec681f3Smrg struct pipe_memory_allocation *pmem, 5917ec681f3Smrg uint64_t offset); 5927ec681f3Smrg 5937ec681f3Smrg /** 5947ec681f3Smrg * Map backing memory. 5957ec681f3Smrg */ 5967ec681f3Smrg void *(*map_memory)(struct pipe_screen *screen, 5977ec681f3Smrg struct pipe_memory_allocation *pmem); 5987ec681f3Smrg 5997ec681f3Smrg /** 6007ec681f3Smrg * Unmap backing memory. 6017ec681f3Smrg */ 6027ec681f3Smrg void (*unmap_memory)(struct pipe_screen *screen, 6037ec681f3Smrg struct pipe_memory_allocation *pmem); 6047ec681f3Smrg 6057ec681f3Smrg /** 6067ec681f3Smrg * Determine whether the screen supports the specified modifier 6077ec681f3Smrg * 6087ec681f3Smrg * Query whether the driver supports a \p modifier in combination with 6097ec681f3Smrg * \p format. If \p external_only is not NULL, the value it points to will 6107ec681f3Smrg * be set to 0 or a non-zero value to indicate whether the modifier and 6117ec681f3Smrg * format combination is supported only with external, or also with non- 6127ec681f3Smrg * external texture targets respectively. The \p external_only parameter is 6137ec681f3Smrg * not used when the function returns false. 6147ec681f3Smrg * 6157ec681f3Smrg * \return true if the format+modifier pair is supported on \p screen, false 6167ec681f3Smrg * otherwise. 6177ec681f3Smrg */ 6187ec681f3Smrg bool (*is_dmabuf_modifier_supported)(struct pipe_screen *screen, 6197ec681f3Smrg uint64_t modifier, enum pipe_format, 6207ec681f3Smrg bool *external_only); 6217ec681f3Smrg 6227ec681f3Smrg /** 6237ec681f3Smrg * Get the number of planes required for a given modifier/format pair. 6247ec681f3Smrg * 6257ec681f3Smrg * If not NULL, this function returns the number of planes needed to 6267ec681f3Smrg * represent \p format in the layout specified by \p modifier, including 6277ec681f3Smrg * any driver-specific auxiliary data planes. 6287ec681f3Smrg * 6297ec681f3Smrg * Must only be called on a modifier supported by the screen for the 6307ec681f3Smrg * specified format. 6317ec681f3Smrg * 6327ec681f3Smrg * If NULL, no auxiliary planes are required for any modifier+format pairs 6337ec681f3Smrg * supported by \p screen. Hence, the plane count can be derived directly 6347ec681f3Smrg * from \p format. 6357ec681f3Smrg * 6367ec681f3Smrg * \return Number of planes needed to store image data in the layout defined 6377ec681f3Smrg * by \p format and \p modifier. 6387ec681f3Smrg */ 6397ec681f3Smrg unsigned int (*get_dmabuf_modifier_planes)(struct pipe_screen *screen, 6407ec681f3Smrg uint64_t modifier, 6417ec681f3Smrg enum pipe_format format); 6427ec681f3Smrg 6437ec681f3Smrg /** 6447ec681f3Smrg * Vertex state CSO functions for precomputing vertex and index buffer 6457ec681f3Smrg * states for display lists. 6467ec681f3Smrg */ 6477ec681f3Smrg pipe_create_vertex_state_func create_vertex_state; 6487ec681f3Smrg pipe_vertex_state_destroy_func vertex_state_destroy; 64901e04c3fSmrg}; 65001e04c3fSmrg 65101e04c3fSmrg 65201e04c3fSmrg/** 65301e04c3fSmrg * Global configuration options for screen creation. 65401e04c3fSmrg */ 65501e04c3fSmrgstruct pipe_screen_config { 6567ec681f3Smrg struct driOptionCache *options; 6577ec681f3Smrg const struct driOptionCache *options_info; 6584a49301eSmrg}; 6594a49301eSmrg 6604a49301eSmrg 6614a49301eSmrg#ifdef __cplusplus 6624a49301eSmrg} 6634a49301eSmrg#endif 6644a49301eSmrg 6654a49301eSmrg#endif /* P_SCREEN_H */ 666