Path: blob/21.2-virgl/src/gallium/include/frontend/api.h
4565 views
/**********************************************************1* Copyright 2010 VMware, Inc. All rights reserved.2*3* Permission is hereby granted, free of charge, to any person4* obtaining a copy of this software and associated documentation5* files (the "Software"), to deal in the Software without6* restriction, including without limitation the rights to use, copy,7* modify, merge, publish, distribute, sublicense, and/or sell copies8* of the Software, and to permit persons to whom the Software is9* furnished to do so, subject to the following conditions:10*11* The above copyright notice and this permission notice shall be12* included in all copies or substantial portions of the Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,15* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF16* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND17* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS18* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN19* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN20* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE21* SOFTWARE.22*23**********************************************************/242526#ifndef _API_H_27#define _API_H_2829#include "pipe/p_format.h"3031/**32* \file API for communication between gallium frontends and supporting33* frontends such as DRI.34*35* This file defines an API to be implemented by both gallium frontends and36* their managers.37*/3839/**40* The supported rendering API.41*/42enum st_api_type {43ST_API_OPENGL,44ST_API_OPENVG,4546ST_API_COUNT47};4849/**50* The profile of a context.51*/52enum st_profile_type53{54ST_PROFILE_DEFAULT, /**< OpenGL compatibility profile */55ST_PROFILE_OPENGL_CORE, /**< OpenGL 3.2+ core profile */56ST_PROFILE_OPENGL_ES1, /**< OpenGL ES 1.x */57ST_PROFILE_OPENGL_ES2 /**< OpenGL ES 2.0 */58};5960/* for profile_mask in st_api */61#define ST_PROFILE_DEFAULT_MASK (1 << ST_PROFILE_DEFAULT)62#define ST_PROFILE_OPENGL_CORE_MASK (1 << ST_PROFILE_OPENGL_CORE)63#define ST_PROFILE_OPENGL_ES1_MASK (1 << ST_PROFILE_OPENGL_ES1)64#define ST_PROFILE_OPENGL_ES2_MASK (1 << ST_PROFILE_OPENGL_ES2)6566/**67* Optional API features.68*/69enum st_api_feature70{71ST_API_FEATURE_MS_VISUALS /**< support for multisample visuals */72};7374/* for feature_mask in st_api */75#define ST_API_FEATURE_MS_VISUALS_MASK (1 << ST_API_FEATURE_MS_VISUALS)7677/**78* New context flags for GL 3.0 and beyond.79*80* Profile information (core vs. compatibilty for OpenGL 3.2+) is communicated81* through the \c st_profile_type, not through flags.82*/83#define ST_CONTEXT_FLAG_DEBUG (1 << 0)84#define ST_CONTEXT_FLAG_FORWARD_COMPATIBLE (1 << 1)85#define ST_CONTEXT_FLAG_ROBUST_ACCESS (1 << 2)86#define ST_CONTEXT_FLAG_RESET_NOTIFICATION_ENABLED (1 << 3)87#define ST_CONTEXT_FLAG_NO_ERROR (1 << 4)88#define ST_CONTEXT_FLAG_RELEASE_NONE (1 << 5)89#define ST_CONTEXT_FLAG_HIGH_PRIORITY (1 << 6)90#define ST_CONTEXT_FLAG_LOW_PRIORITY (1 << 7)9192/**93* Reasons that context creation might fail.94*/95enum st_context_error {96ST_CONTEXT_SUCCESS = 0,97ST_CONTEXT_ERROR_NO_MEMORY,98ST_CONTEXT_ERROR_BAD_API,99ST_CONTEXT_ERROR_BAD_VERSION,100ST_CONTEXT_ERROR_BAD_FLAG,101ST_CONTEXT_ERROR_UNKNOWN_ATTRIBUTE,102ST_CONTEXT_ERROR_UNKNOWN_FLAG103};104105/**106* Used in st_context_iface->teximage.107*/108enum st_texture_type {109ST_TEXTURE_1D,110ST_TEXTURE_2D,111ST_TEXTURE_3D,112ST_TEXTURE_RECT113};114115/**116* Available attachments of framebuffer.117*/118enum st_attachment_type {119ST_ATTACHMENT_FRONT_LEFT,120ST_ATTACHMENT_BACK_LEFT,121ST_ATTACHMENT_FRONT_RIGHT,122ST_ATTACHMENT_BACK_RIGHT,123ST_ATTACHMENT_DEPTH_STENCIL,124ST_ATTACHMENT_ACCUM,125126ST_ATTACHMENT_COUNT,127ST_ATTACHMENT_INVALID = -1128};129130/* for buffer_mask in st_visual */131#define ST_ATTACHMENT_FRONT_LEFT_MASK (1 << ST_ATTACHMENT_FRONT_LEFT)132#define ST_ATTACHMENT_BACK_LEFT_MASK (1 << ST_ATTACHMENT_BACK_LEFT)133#define ST_ATTACHMENT_FRONT_RIGHT_MASK (1 << ST_ATTACHMENT_FRONT_RIGHT)134#define ST_ATTACHMENT_BACK_RIGHT_MASK (1 << ST_ATTACHMENT_BACK_RIGHT)135#define ST_ATTACHMENT_DEPTH_STENCIL_MASK (1 << ST_ATTACHMENT_DEPTH_STENCIL)136#define ST_ATTACHMENT_ACCUM_MASK (1 << ST_ATTACHMENT_ACCUM)137138/**139* Flush flags.140*/141#define ST_FLUSH_FRONT (1 << 0)142#define ST_FLUSH_END_OF_FRAME (1 << 1)143#define ST_FLUSH_WAIT (1 << 2)144#define ST_FLUSH_FENCE_FD (1 << 3)145146/**147* State invalidation flags to notify frontends that states have been changed148* behind their back.149*/150#define ST_INVALIDATE_FS_SAMPLER_VIEWS (1 << 0)151#define ST_INVALIDATE_FS_CONSTBUF0 (1 << 1)152#define ST_INVALIDATE_VS_CONSTBUF0 (1 << 2)153#define ST_INVALIDATE_VERTEX_BUFFERS (1 << 3)154155/**156* Value to st_manager->get_param function.157*/158enum st_manager_param {159/**160* The DRI frontend on old libGL's doesn't do the right thing161* with regards to invalidating the framebuffers.162*163* For the GL gallium frontend that means that it needs to invalidate164* the framebuffer in glViewport itself.165*/166ST_MANAGER_BROKEN_INVALIDATE167};168169struct pipe_context;170struct pipe_resource;171struct pipe_fence_handle;172struct util_queue_monitoring;173174/**175* Used in st_manager_iface->get_egl_image.176*/177struct st_egl_image178{179/* this is owned by the caller */180struct pipe_resource *texture;181182/* format only differs from texture->format for multi-planar (YUV): */183enum pipe_format format;184185unsigned level;186unsigned layer;187/* GL internal format. */188unsigned internalformat;189};190191/**192* Represent the visual of a framebuffer.193*/194struct st_visual195{196/**197* Available buffers. Bitfield of ST_ATTACHMENT_*_MASK bits.198*/199unsigned buffer_mask;200201/**202* Buffer formats. The formats are always set even when the buffer is203* not available.204*/205enum pipe_format color_format;206enum pipe_format depth_stencil_format;207enum pipe_format accum_format;208unsigned samples;209};210211212/**213* Configuration options from driconf214*/215struct st_config_options216{217bool disable_blend_func_extended;218bool disable_glsl_line_continuations;219bool disable_arb_gpu_shader5;220bool force_glsl_extensions_warn;221unsigned force_glsl_version;222bool allow_extra_pp_tokens;223bool allow_glsl_extension_directive_midshader;224bool allow_glsl_120_subset_in_110;225bool allow_glsl_builtin_const_expression;226bool allow_glsl_relaxed_es;227bool allow_glsl_builtin_variable_redeclaration;228bool allow_higher_compat_version;229bool glsl_ignore_write_to_readonly_var;230bool glsl_zero_init;231bool vs_position_always_invariant;232bool force_glsl_abs_sqrt;233bool allow_glsl_cross_stage_interpolation_mismatch;234bool allow_draw_out_of_order;235bool allow_incorrect_primitive_id;236bool ignore_map_unsynchronized;237bool force_integer_tex_nearest;238bool force_gl_names_reuse;239bool transcode_etc;240bool transcode_astc;241char *force_gl_vendor;242unsigned char config_options_sha1[20];243};244245/**246* Represent the attributes of a context.247*/248struct st_context_attribs249{250/**251* The profile and minimal version to support.252*253* The valid profiles and versions are rendering API dependent. The latest254* version satisfying the request should be returned.255*/256enum st_profile_type profile;257int major, minor;258259/** Mask of ST_CONTEXT_FLAG_x bits */260unsigned flags;261262/**263* The visual of the framebuffers the context will be bound to.264*/265struct st_visual visual;266267/**268* Configuration options.269*/270struct st_config_options options;271};272273struct st_context_iface;274struct st_manager;275276/**277* Represent a windowing system drawable.278*279* The framebuffer is implemented by the frontend manager and280* used by gallium frontends.281*282* Instead of the winsys poking into the frontend context to figure283* out what buffers that might be needed in the future by the frontend284* context, it calls into the framebuffer to get the textures.285*286* This structure along with the notify_invalid_framebuffer287* allows framebuffers to be shared between different threads288* but at the same make the API context free from thread289* synchronization primitves, with the exception of a small290* atomic flag used for notification of framebuffer dirty status.291*292* The thread synchronization is put inside the framebuffer293* and only called once the framebuffer has become dirty.294*/295struct st_framebuffer_iface296{297/**298* Atomic stamp which changes when framebuffers need to be updated.299*/300int32_t stamp;301302/**303* Identifier that uniquely identifies the framebuffer interface object.304*/305uint32_t ID;306307/**308* The frontend manager that manages this object.309*/310struct st_manager *state_manager;311312/**313* Available for the frontend manager to use.314*/315void *st_manager_private;316317/**318* The visual of a framebuffer.319*/320const struct st_visual *visual;321322/**323* Flush the front buffer.324*325* On some window systems, changes to the front buffers are not immediately326* visible. They need to be flushed.327*328* @att is one of the front buffer attachments.329*/330bool (*flush_front)(struct st_context_iface *stctx,331struct st_framebuffer_iface *stfbi,332enum st_attachment_type statt);333334/**335* the gallium frontend asks for the textures it needs.336*337* It should try to only ask for attachments that it currently renders338* to, thus allowing the winsys to delay the allocation of textures not339* needed. For example front buffer attachments are not needed if you340* only do back buffer rendering.341*342* The implementor of this function needs to also ensure343* thread safty as this call might be done from multiple threads.344*345* The returned textures are owned by the caller. They should be346* unreferenced when no longer used. If this function is called multiple347* times with different sets of attachments, those buffers not included in348* the last call might be destroyed. This behavior might change in the349* future.350*/351bool (*validate)(struct st_context_iface *stctx,352struct st_framebuffer_iface *stfbi,353const enum st_attachment_type *statts,354unsigned count,355struct pipe_resource **out);356bool (*flush_swapbuffers) (struct st_context_iface *stctx,357struct st_framebuffer_iface *stfbi);358};359360/**361* Represent a rendering context.362*363* This entity is created from st_api and used by the frontend manager.364*/365struct st_context_iface366{367/**368* Available for the gallium frontend and the manager to use.369*/370void *st_context_private;371void *st_manager_private;372373/**374* The frontend manager that manages this object.375*/376struct st_manager *state_manager;377378/**379* The CSO context associated with this context in case we need to draw380* something before swap buffers.381*/382struct cso_context *cso_context;383384/**385* The gallium context.386*/387struct pipe_context *pipe;388389/**390* Should we flush front buffer?391*/392bool should_flush_frontbuffer;393394/**395* Destroy the context.396*/397void (*destroy)(struct st_context_iface *stctxi);398399/**400* Flush all drawing from context to the pipe also flushes the pipe.401*/402void (*flush)(struct st_context_iface *stctxi, unsigned flags,403struct pipe_fence_handle **fence,404void (*notify_before_flush_cb) (void*),405void* notify_before_flush_cb_args);406407/**408* Replace the texture image of a texture object at the specified level.409*410* This function is optional.411*/412bool (*teximage)(struct st_context_iface *stctxi,413enum st_texture_type target,414int level, enum pipe_format internal_format,415struct pipe_resource *tex, bool mipmap);416417/**418* Used to implement glXCopyContext.419*/420void (*copy)(struct st_context_iface *stctxi,421struct st_context_iface *stsrci, unsigned mask);422423/**424* Used to implement wglShareLists.425*/426bool (*share)(struct st_context_iface *stctxi,427struct st_context_iface *stsrci);428429/**430* Start the thread if the API has a worker thread.431* Called after the context has been created and fully initialized on both432* sides (e.g. st/mesa and st/dri).433*/434void (*start_thread)(struct st_context_iface *stctxi);435436/**437* If the API is multithreaded, wait for all queued commands to complete.438* Called from the main thread.439*/440void (*thread_finish)(struct st_context_iface *stctxi);441442/**443* Invalidate states to notify the frontend that states have been changed444* behind its back.445*/446void (*invalidate_state)(struct st_context_iface *stctxi, unsigned flags);447};448449450/**451* Represent a frontend manager.452*453* This interface is implemented by the frontend manager. It corresponds454* to a "display" in the window system.455*/456struct st_manager457{458struct pipe_screen *screen;459460/**461* Look up and return the info of an EGLImage.462*463* This is used to implement for example EGLImageTargetTexture2DOES.464* The GLeglImageOES agrument of that call is passed directly to this465* function call and the information needed to access this is returned466* in the given struct out.467*468* @smapi: manager owning the caller context469* @stctx: caller context470* @egl_image: EGLImage that caller recived471* @out: return struct filled out with access information.472*473* This function is optional.474*/475bool (*get_egl_image)(struct st_manager *smapi,476void *egl_image,477struct st_egl_image *out);478479/**480* Query an manager param.481*/482int (*get_param)(struct st_manager *smapi,483enum st_manager_param param);484485/**486* Call the loader function setBackgroundContext. Called from the worker487* thread.488*/489void (*set_background_context)(struct st_context_iface *stctxi,490struct util_queue_monitoring *queue_info);491492/**493* Destroy any private data used by the frontend manager.494*/495void (*destroy)(struct st_manager *smapi);496497/**498* Available for the frontend manager to use.499*/500void *st_manager_private;501};502503/**504* Represent a rendering API such as OpenGL or OpenVG.505*506* Implemented by the gallium frontend and used by the frontend manager.507*/508struct st_api509{510/**511* The name of the rendering API. This is informative.512*/513const char *name;514515/**516* The supported rendering API.517*/518enum st_api_type api;519520/**521* The supported profiles. Tested with ST_PROFILE_*_MASK.522*/523unsigned profile_mask;524525/**526* The supported optional features. Tested with ST_FEATURE_*_MASK.527*/528unsigned feature_mask;529530/**531* Destroy the API.532*/533void (*destroy)(struct st_api *stapi);534535/**536* Query supported OpenGL versions. (if applicable)537* The format is (major*10+minor).538*/539void (*query_versions)(struct st_api *stapi, struct st_manager *sm,540struct st_config_options *options,541int *gl_core_version,542int *gl_compat_version,543int *gl_es1_version,544int *gl_es2_version);545546/**547* Create a rendering context.548*/549struct st_context_iface *(*create_context)(struct st_api *stapi,550struct st_manager *smapi,551const struct st_context_attribs *attribs,552enum st_context_error *error,553struct st_context_iface *stsharei);554555/**556* Bind the context to the calling thread with draw and read as drawables.557*558* The framebuffers might be NULL, or might have different visuals than the559* context does.560*/561bool (*make_current)(struct st_api *stapi,562struct st_context_iface *stctxi,563struct st_framebuffer_iface *stdrawi,564struct st_framebuffer_iface *streadi);565566/**567* Get the currently bound context in the calling thread.568*/569struct st_context_iface *(*get_current)(struct st_api *stapi);570571/**572* Notify the st manager the framebuffer interface object573* is no longer valid.574*/575void (*destroy_drawable)(struct st_api *stapi,576struct st_framebuffer_iface *stfbi);577};578579/**580* Return true if the visual has the specified buffers.581*/582static inline bool583st_visual_have_buffers(const struct st_visual *visual, unsigned mask)584{585return ((visual->buffer_mask & mask) == mask);586}587588#endif /* _API_H_ */589590591