Path: blob/21.2-virgl/src/gallium/include/pipe/p_screen.h
4566 views
/**************************************************************************1*2* Copyright 2007 VMware, Inc.3* All Rights Reserved.4*5* Permission is hereby granted, free of charge, to any person obtaining a6* copy of this software and associated documentation files (the7* "Software"), to deal in the Software without restriction, including8* without limitation the rights to use, copy, modify, merge, publish,9* distribute, sub license, and/or sell copies of the Software, and to10* permit persons to whom the Software is furnished to do so, subject to11* the following conditions:12*13* The above copyright notice and this permission notice (including the14* next paragraph) shall be included in all copies or substantial portions15* of the Software.16*17* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS18* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF19* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.20* IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR21* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,22* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE23* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.24*25**************************************************************************/2627/**28* @file29*30* Screen, Adapter or GPU31*32* These are driver functions/facilities that are context independent.33*/343536#ifndef P_SCREEN_H37#define P_SCREEN_H383940#include "pipe/p_compiler.h"41#include "pipe/p_format.h"42#include "pipe/p_defines.h"43#include "pipe/p_video_enums.h"44454647#ifdef __cplusplus48extern "C" {49#endif505152/** Opaque types */53struct winsys_handle;54struct pipe_fence_handle;55struct pipe_resource;56struct pipe_surface;57struct pipe_transfer;58struct pipe_box;59struct pipe_memory_info;60struct disk_cache;61struct driOptionCache;62struct u_transfer_helper;6364/**65* Gallium screen/adapter context. Basically everything66* hardware-specific that doesn't actually require a rendering67* context.68*/69struct pipe_screen {70/**71* Atomically incremented by drivers to track the number of contexts.72* If it's 0, it can be assumed that contexts are not tracked.73* Used by some places to skip locking if num_contexts == 1.74*/75unsigned num_contexts;7677/**78* For drivers using u_transfer_helper:79*/80struct u_transfer_helper *transfer_helper;8182void (*destroy)( struct pipe_screen * );8384const char *(*get_name)( struct pipe_screen * );8586const char *(*get_vendor)( struct pipe_screen * );8788/**89* Returns the device vendor.90*91* The returned value should return the actual device vendor/manufacturer,92* rather than a potentially generic driver string.93*/94const char *(*get_device_vendor)( struct pipe_screen * );9596/**97* Query an integer-valued capability/parameter/limit98* \param param one of PIPE_CAP_x99*/100int (*get_param)( struct pipe_screen *, enum pipe_cap param );101102/**103* Query a float-valued capability/parameter/limit104* \param param one of PIPE_CAP_x105*/106float (*get_paramf)( struct pipe_screen *, enum pipe_capf param );107108/**109* Query a per-shader-stage integer-valued capability/parameter/limit110* \param param one of PIPE_CAP_x111*/112int (*get_shader_param)( struct pipe_screen *, enum pipe_shader_type shader,113enum pipe_shader_cap param );114115/**116* Query an integer-valued capability/parameter/limit for a codec/profile117* \param param one of PIPE_VIDEO_CAP_x118*/119int (*get_video_param)( struct pipe_screen *,120enum pipe_video_profile profile,121enum pipe_video_entrypoint entrypoint,122enum pipe_video_cap param );123124/**125* Query a compute-specific capability/parameter/limit.126* \param ir_type shader IR type for which the param applies, or don't care127* if the param is not shader related128* \param param one of PIPE_COMPUTE_CAP_x129* \param ret pointer to a preallocated buffer that will be130* initialized to the parameter value, or NULL.131* \return size in bytes of the parameter value that would be132* returned.133*/134int (*get_compute_param)(struct pipe_screen *,135enum pipe_shader_ir ir_type,136enum pipe_compute_cap param,137void *ret);138139/**140* Get the sample pixel grid's size. This function requires141* PIPE_CAP_PROGRAMMABLE_SAMPLE_LOCATIONS to be callable.142*143* \param sample_count - total number of samples144* \param out_width - the width of the pixel grid145* \param out_height - the height of the pixel grid146*/147void (*get_sample_pixel_grid)(struct pipe_screen *, unsigned sample_count,148unsigned *out_width, unsigned *out_height);149150/**151* Query a timestamp in nanoseconds. The returned value should match152* PIPE_QUERY_TIMESTAMP. This function returns immediately and doesn't153* wait for rendering to complete (which cannot be achieved with queries).154*/155uint64_t (*get_timestamp)(struct pipe_screen *);156157/**158* Create a context.159*160* \param screen pipe screen161* \param priv a pointer to set in pipe_context::priv162* \param flags a mask of PIPE_CONTEXT_* flags163*/164struct pipe_context * (*context_create)(struct pipe_screen *screen,165void *priv, unsigned flags);166167/**168* Check if the given pipe_format is supported as a texture or169* drawing surface.170* \param bindings bitmask of PIPE_BIND_*171*/172bool (*is_format_supported)( struct pipe_screen *,173enum pipe_format format,174enum pipe_texture_target target,175unsigned sample_count,176unsigned storage_sample_count,177unsigned bindings );178179/**180* Check if the given pipe_format is supported as output for this codec/profile.181* \param profile profile to check, may also be PIPE_VIDEO_PROFILE_UNKNOWN182*/183bool (*is_video_format_supported)( struct pipe_screen *,184enum pipe_format format,185enum pipe_video_profile profile,186enum pipe_video_entrypoint entrypoint );187188/**189* Check if we can actually create the given resource (test the dimension,190* overall size, etc). Used to implement proxy textures.191* \return TRUE if size is OK, FALSE if too large.192*/193bool (*can_create_resource)(struct pipe_screen *screen,194const struct pipe_resource *templat);195196/**197* Create a new texture object, using the given template info.198*/199struct pipe_resource * (*resource_create)(struct pipe_screen *,200const struct pipe_resource *templat);201202struct pipe_resource * (*resource_create_front)(struct pipe_screen *,203const struct pipe_resource *templat,204const void *map_front_private);205206/**207* Create a texture from a winsys_handle. The handle is often created in208* another process by first creating a pipe texture and then calling209* resource_get_handle.210*211* NOTE: in the case of WINSYS_HANDLE_TYPE_FD handles, the caller212* retains ownership of the FD. (This is consistent with213* EGL_EXT_image_dma_buf_import)214*215* \param usage A combination of PIPE_HANDLE_USAGE_* flags.216*/217struct pipe_resource * (*resource_from_handle)(struct pipe_screen *,218const struct pipe_resource *templat,219struct winsys_handle *handle,220unsigned usage);221222/**223* Create a resource from user memory. This maps the user memory into224* the device address space.225*/226struct pipe_resource * (*resource_from_user_memory)(struct pipe_screen *,227const struct pipe_resource *t,228void *user_memory);229230/**231* Unlike pipe_resource::bind, which describes what gallium frontends want,232* resources can have much greater capabilities in practice, often implied233* by the tiling layout or memory placement. This function allows querying234* whether a capability is supported beyond what was requested by state235* trackers. It's also useful for querying capabilities of imported236* resources where the capabilities are unknown at first.237*238* Only these flags are allowed:239* - PIPE_BIND_SCANOUT240* - PIPE_BIND_CURSOR241* - PIPE_BIND_LINEAR242*/243bool (*check_resource_capability)(struct pipe_screen *screen,244struct pipe_resource *resource,245unsigned bind);246247/**248* Get a winsys_handle from a texture. Some platforms/winsys requires249* that the texture is created with a special usage flag like250* DISPLAYTARGET or PRIMARY.251*252* The context parameter can optionally be used to flush the resource and253* the context to make sure the resource is coherent with whatever user254* will use it. Some drivers may also use the context to convert255* the resource into a format compatible for sharing. The use case is256* OpenGL-OpenCL interop. The context parameter is allowed to be NULL.257*258* NOTE: for multi-planar resources (which may or may not have the planes259* chained through the pipe_resource next pointer) the frontend will260* always call this function with the first resource of the chain. It is261* the pipe drivers responsibility to walk the resources as needed when262* called with handle->plane != 0.263*264* NOTE: in the case of WINSYS_HANDLE_TYPE_FD handles, the caller265* takes ownership of the FD. (This is consistent with266* EGL_MESA_image_dma_buf_export)267*268* \param usage A combination of PIPE_HANDLE_USAGE_* flags.269*/270bool (*resource_get_handle)(struct pipe_screen *,271struct pipe_context *context,272struct pipe_resource *tex,273struct winsys_handle *handle,274unsigned usage);275276/**277* Get info for the given pipe resource without the need to get a278* winsys_handle.279*280* The context parameter can optionally be used to flush the resource and281* the context to make sure the resource is coherent with whatever user282* will use it. Some drivers may also use the context to convert283* the resource into a format compatible for sharing. The context parameter284* is allowed to be NULL.285*/286bool (*resource_get_param)(struct pipe_screen *screen,287struct pipe_context *context,288struct pipe_resource *resource,289unsigned plane,290unsigned layer,291unsigned level,292enum pipe_resource_param param,293unsigned handle_usage,294uint64_t *value);295296/**297* Get stride and offset for the given pipe resource without the need to get298* a winsys_handle.299*/300void (*resource_get_info)(struct pipe_screen *screen,301struct pipe_resource *resource,302unsigned *stride,303unsigned *offset);304305/**306* Mark the resource as changed so derived internal resources will be307* recreated on next use.308*309* This is necessary when reimporting external images that can't be directly310* used as texture sampler source, to avoid sampling from old copies.311*/312void (*resource_changed)(struct pipe_screen *, struct pipe_resource *pt);313314void (*resource_destroy)(struct pipe_screen *,315struct pipe_resource *pt);316317318/**319* Do any special operations to ensure frontbuffer contents are320* displayed, eg copy fake frontbuffer.321* \param winsys_drawable_handle an opaque handle that the calling context322* gets out-of-band323* \param subbox an optional sub region to flush324*/325void (*flush_frontbuffer)( struct pipe_screen *screen,326struct pipe_context *ctx,327struct pipe_resource *resource,328unsigned level, unsigned layer,329void *winsys_drawable_handle,330struct pipe_box *subbox );331332/** Set ptr = fence, with reference counting */333void (*fence_reference)( struct pipe_screen *screen,334struct pipe_fence_handle **ptr,335struct pipe_fence_handle *fence );336337/**338* Wait for the fence to finish.339*340* If the fence was created with PIPE_FLUSH_DEFERRED, and the context is341* still unflushed, and the ctx parameter of fence_finish is equal to342* the context where the fence was created, fence_finish will flush343* the context prior to waiting for the fence.344*345* In all other cases, the ctx parameter has no effect.346*347* \param timeout in nanoseconds (may be PIPE_TIMEOUT_INFINITE).348*/349bool (*fence_finish)(struct pipe_screen *screen,350struct pipe_context *ctx,351struct pipe_fence_handle *fence,352uint64_t timeout);353354/**355* For fences created with PIPE_FLUSH_FENCE_FD (exported fd) or356* by create_fence_fd() (imported fd), return the native fence fd357* associated with the fence. This may return -1 for fences358* created with PIPE_FLUSH_DEFERRED if the fence command has not359* been flushed yet.360*/361int (*fence_get_fd)(struct pipe_screen *screen,362struct pipe_fence_handle *fence);363364/**365* Returns a driver-specific query.366*367* If \p info is NULL, the number of available queries is returned.368* Otherwise, the driver query at the specified \p index is returned369* in \p info. The function returns non-zero on success.370*/371int (*get_driver_query_info)(struct pipe_screen *screen,372unsigned index,373struct pipe_driver_query_info *info);374375/**376* Returns a driver-specific query group.377*378* If \p info is NULL, the number of available groups is returned.379* Otherwise, the driver query group at the specified \p index is returned380* in \p info. The function returns non-zero on success.381*/382int (*get_driver_query_group_info)(struct pipe_screen *screen,383unsigned index,384struct pipe_driver_query_group_info *info);385386/**387* Query information about memory usage.388*/389void (*query_memory_info)(struct pipe_screen *screen,390struct pipe_memory_info *info);391392/**393* Get IR specific compiler options struct. For PIPE_SHADER_IR_NIR this394* returns a 'struct nir_shader_compiler_options'. Drivers reporting395* NIR as the preferred IR must implement this.396*/397const void *(*get_compiler_options)(struct pipe_screen *screen,398enum pipe_shader_ir ir,399enum pipe_shader_type shader);400401/**402* Returns a pointer to a driver-specific on-disk shader cache. If the403* driver failed to create the cache or does not support an on-disk shader404* cache NULL is returned. The callback itself may also be NULL if the405* driver doesn't support an on-disk shader cache.406*/407struct disk_cache *(*get_disk_shader_cache)(struct pipe_screen *screen);408409/**410* Create a new texture object from the given template info, taking411* format modifiers into account. \p modifiers specifies a list of format412* modifier tokens, as defined in drm_fourcc.h. The driver then picks the413* best modifier among these and creates the resource. \p count must414* contain the size of \p modifiers array.415*416* Returns NULL if an entry in \p modifiers is unsupported by the driver,417* or if only DRM_FORMAT_MOD_INVALID is provided.418*/419struct pipe_resource * (*resource_create_with_modifiers)(420struct pipe_screen *,421const struct pipe_resource *templat,422const uint64_t *modifiers, int count);423424/**425* Get supported modifiers for a format.426* If \p max is 0, the total number of supported modifiers for the supplied427* format is returned in \p count, with no modification to \p modifiers.428* Otherwise, \p modifiers is filled with upto \p max supported modifier429* codes, and \p count with the number of modifiers copied.430* The \p external_only array is used to return whether the format and431* modifier combination can only be used with an external texture target.432*/433void (*query_dmabuf_modifiers)(struct pipe_screen *screen,434enum pipe_format format, int max,435uint64_t *modifiers,436unsigned int *external_only, int *count);437438/**439* Create a memory object from a winsys handle440*441* The underlying memory is most often allocated in by a foregin API.442* Then the underlying memory object is then exported through interfaces443* compatible with EXT_external_resources.444*445* Note: For WINSYS_HANDLE_TYPE_FD handles, the caller retains ownership446* of the fd.447*448* \param handle A handle representing the memory object to import449*/450struct pipe_memory_object *(*memobj_create_from_handle)(struct pipe_screen *screen,451struct winsys_handle *handle,452bool dedicated);453454/**455* Destroy a memory object456*457* \param memobj The memory object to destroy458*/459void (*memobj_destroy)(struct pipe_screen *screen,460struct pipe_memory_object *memobj);461462/**463* Create a texture from a memory object464*465* \param t texture template466* \param memobj The memory object used to back the texture467*/468struct pipe_resource * (*resource_from_memobj)(struct pipe_screen *screen,469const struct pipe_resource *t,470struct pipe_memory_object *memobj,471uint64_t offset);472473/**474* Fill @uuid with a unique driver identifier475*476* \param uuid pointer to a memory region of PIPE_UUID_SIZE bytes477*/478void (*get_driver_uuid)(struct pipe_screen *screen, char *uuid);479480/**481* Fill @uuid with a unique device identifier482*483* \param uuid pointer to a memory region of PIPE_UUID_SIZE bytes484*/485void (*get_device_uuid)(struct pipe_screen *screen, char *uuid);486487/**488* Set the maximum number of parallel shader compiler threads.489*/490void (*set_max_shader_compiler_threads)(struct pipe_screen *screen,491unsigned max_threads);492493/**494* Return whether parallel shader compilation has finished.495*/496bool (*is_parallel_shader_compilation_finished)(struct pipe_screen *screen,497void *shader,498unsigned shader_type);499500/**501* Set the damage region (called when KHR_partial_update() is invoked).502* This function is passed an array of rectangles encoding the damage area.503* rects are using the bottom-left origin convention.504* nrects = 0 means 'reset the damage region'. What 'reset' implies is HW505* specific. For tile-based renderers, the damage extent is typically set506* to cover the whole resource with no damage rect (or a 0-size damage507* rect). This way, the existing resource content is reloaded into the508* local tile buffer for every tile thus making partial tile update509* possible. For HW operating in immediate mode, this reset operation is510* likely to be a NOOP.511*/512void (*set_damage_region)(struct pipe_screen *screen,513struct pipe_resource *resource,514unsigned int nrects,515const struct pipe_box *rects);516517/**518* Run driver-specific NIR lowering and optimization passes.519*520* gallium frontends should call this before passing shaders to drivers,521* and ideally also before shader caching.522*523* \param optimize Whether the input shader hasn't been optimized and524* should be.525*/526void (*finalize_nir)(struct pipe_screen *screen, void *nir, bool optimize);527528/*Separated memory/resource allocations interfaces for Vulkan */529530/**531* Create a resource, and retrieve the required size for it but don't allocate532* any backing memory.533*/534struct pipe_resource * (*resource_create_unbacked)(struct pipe_screen *,535const struct pipe_resource *templat,536uint64_t *size_required);537538/**539* Allocate backing memory to be bound to resources.540*/541struct pipe_memory_allocation *(*allocate_memory)(struct pipe_screen *screen,542uint64_t size);543/**544* Free previously allocated backing memory.545*/546void (*free_memory)(struct pipe_screen *screen,547struct pipe_memory_allocation *);548549/**550* Bind memory to a resource.551*/552bool (*resource_bind_backing)(struct pipe_screen *screen,553struct pipe_resource *pt,554struct pipe_memory_allocation *pmem,555uint64_t offset);556557/**558* Map backing memory.559*/560void *(*map_memory)(struct pipe_screen *screen,561struct pipe_memory_allocation *pmem);562563/**564* Unmap backing memory.565*/566void (*unmap_memory)(struct pipe_screen *screen,567struct pipe_memory_allocation *pmem);568569/**570* Determine whether the screen supports the specified modifier571*572* Query whether the driver supports a \p modifier in combination with573* \p format. If \p external_only is not NULL, the value it points to will574* be set to 0 or a non-zero value to indicate whether the modifier and575* format combination is supported only with external, or also with non-576* external texture targets respectively. The \p external_only parameter is577* not used when the function returns false.578*579* \return true if the format+modifier pair is supported on \p screen, false580* otherwise.581*/582bool (*is_dmabuf_modifier_supported)(struct pipe_screen *screen,583uint64_t modifier, enum pipe_format,584bool *external_only);585586/**587* Get the number of planes required for a given modifier/format pair.588*589* If not NULL, this function returns the number of planes needed to590* represent \p format in the layout specified by \p modifier, including591* any driver-specific auxiliary data planes.592*593* Must only be called on a modifier supported by the screen for the594* specified format.595*596* If NULL, no auxiliary planes are required for any modifier+format pairs597* supported by \p screen. Hence, the plane count can be derived directly598* from \p format.599*600* \return Number of planes needed to store image data in the layout defined601* by \p format and \p modifier.602*/603unsigned int (*get_dmabuf_modifier_planes)(struct pipe_screen *screen,604uint64_t modifier,605enum pipe_format format);606};607608609/**610* Global configuration options for screen creation.611*/612struct pipe_screen_config {613const struct driOptionCache *options;614};615616617#ifdef __cplusplus618}619#endif620621#endif /* P_SCREEN_H */622623624