1 /********************************************************** 2 * Copyright 2010 VMware, Inc. All rights reserved. 3 * 4 * Permission is hereby granted, free of charge, to any person 5 * obtaining a copy of this software and associated documentation 6 * files (the "Software"), to deal in the Software without 7 * restriction, including without limitation the rights to use, copy, 8 * modify, merge, publish, distribute, sublicense, and/or sell copies 9 * of the Software, and to permit persons to whom the Software is 10 * furnished to do so, subject to the following conditions: 11 * 12 * The above copyright notice and this permission notice shall be 13 * included in all copies or substantial portions of the Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 * SOFTWARE. 23 * 24 **********************************************************/ 25 26 27 #ifndef _API_H_ 28 #define _API_H_ 29 30 #include "util/format/u_formats.h" 31 32 struct st_context; 33 34 /** 35 * \file API for communication between gallium frontends and supporting 36 * frontends such as DRI. 37 * 38 * This file defines the API that the GL frontend uses to talk to 39 * the DRI/GLX/WGL frontends. 40 */ 41 42 43 /** 44 * Context flags. 45 */ 46 #define ST_CONTEXT_FLAG_DEBUG (1 << 0) 47 #define ST_CONTEXT_FLAG_FORWARD_COMPATIBLE (1 << 1) 48 #define ST_CONTEXT_FLAG_NO_ERROR (1 << 2) 49 #define ST_CONTEXT_FLAG_RELEASE_NONE (1 << 3) 50 51 52 /** 53 * Reasons that context creation might fail. 54 */ 55 enum st_context_error { 56 ST_CONTEXT_SUCCESS = 0, 57 ST_CONTEXT_ERROR_NO_MEMORY, 58 ST_CONTEXT_ERROR_BAD_VERSION, 59 }; 60 61 /** 62 * Available attachments of framebuffer. 63 */ 64 enum st_attachment_type { 65 ST_ATTACHMENT_FRONT_LEFT, 66 ST_ATTACHMENT_BACK_LEFT, 67 ST_ATTACHMENT_FRONT_RIGHT, 68 ST_ATTACHMENT_BACK_RIGHT, 69 ST_ATTACHMENT_DEPTH_STENCIL, 70 ST_ATTACHMENT_ACCUM, 71 72 ST_ATTACHMENT_COUNT, 73 ST_ATTACHMENT_INVALID = -1 74 }; 75 76 /* for buffer_mask in st_visual */ 77 #define ST_ATTACHMENT_FRONT_LEFT_MASK (1 << ST_ATTACHMENT_FRONT_LEFT) 78 #define ST_ATTACHMENT_BACK_LEFT_MASK (1 << ST_ATTACHMENT_BACK_LEFT) 79 #define ST_ATTACHMENT_FRONT_RIGHT_MASK (1 << ST_ATTACHMENT_FRONT_RIGHT) 80 #define ST_ATTACHMENT_BACK_RIGHT_MASK (1 << ST_ATTACHMENT_BACK_RIGHT) 81 #define ST_ATTACHMENT_DEPTH_STENCIL_MASK (1 << ST_ATTACHMENT_DEPTH_STENCIL) 82 #define ST_ATTACHMENT_ACCUM_MASK (1 << ST_ATTACHMENT_ACCUM) 83 84 /** 85 * Flush flags. 86 */ 87 #define ST_FLUSH_FRONT (1 << 0) 88 #define ST_FLUSH_END_OF_FRAME (1 << 1) 89 #define ST_FLUSH_WAIT (1 << 2) 90 #define ST_FLUSH_FENCE_FD (1 << 3) 91 92 /** 93 * State invalidation flags to notify st_context that states have been changed 94 * behind their back. 95 */ 96 #define ST_INVALIDATE_FS_SAMPLER_VIEWS (1 << 0) 97 #define ST_INVALIDATE_FS_CONSTBUF0 (1 << 1) 98 #define ST_INVALIDATE_VS_CONSTBUF0 (1 << 2) 99 #define ST_INVALIDATE_VERTEX_BUFFERS (1 << 3) 100 #define ST_INVALIDATE_FB_STATE (1 << 4) 101 102 /** 103 * Value to pipe_frontend_streen::get_param function. 104 */ 105 enum st_manager_param { 106 /** 107 * The DRI frontend on old libGL's doesn't do the right thing 108 * with regards to invalidating the framebuffers. 109 * 110 * For the GL gallium frontend that means that it needs to invalidate 111 * the framebuffer in glViewport itself. 112 */ 113 ST_MANAGER_BROKEN_INVALIDATE 114 }; 115 116 struct pipe_resource; 117 struct util_queue_monitoring; 118 119 /** 120 * Used in pipe_frontend_screen::get_egl_image. 121 */ 122 struct st_egl_image 123 { 124 /* this is owned by the caller */ 125 struct pipe_resource *texture; 126 127 /* format only differs from texture->format for multi-planar (YUV): */ 128 enum pipe_format format; 129 130 unsigned level; 131 unsigned layer; 132 /* GL internal format. */ 133 unsigned internalformat; 134 135 /* one of __DRI_YUV_COLOR_SPACE_* */ 136 unsigned yuv_color_space; 137 138 /* one of __DRI_YUV_RANGE_* */ 139 unsigned yuv_range; 140 141 bool imported_dmabuf; 142 }; 143 144 /** 145 * Represent the visual of a framebuffer. 146 */ 147 struct st_visual 148 { 149 /** 150 * Available buffers. Bitfield of ST_ATTACHMENT_*_MASK bits. 151 */ 152 unsigned buffer_mask; 153 154 /** 155 * Buffer formats. The formats are always set even when the buffer is 156 * not available. 157 */ 158 enum pipe_format color_format; 159 enum pipe_format depth_stencil_format; 160 enum pipe_format accum_format; 161 unsigned samples; 162 }; 163 164 165 /** 166 * Configuration options from driconf 167 */ 168 struct st_config_options 169 { 170 bool disable_blend_func_extended; 171 bool disable_glsl_line_continuations; 172 bool disable_arb_gpu_shader5; 173 bool disable_uniform_array_resize; 174 char *alias_shader_extension; 175 bool allow_vertex_texture_bias; 176 bool force_compat_shaders; 177 bool force_glsl_extensions_warn; 178 unsigned force_glsl_version; 179 bool allow_extra_pp_tokens; 180 bool allow_glsl_extension_directive_midshader; 181 bool allow_glsl_120_subset_in_110; 182 bool allow_glsl_builtin_const_expression; 183 bool allow_glsl_relaxed_es; 184 bool allow_glsl_builtin_variable_redeclaration; 185 bool allow_higher_compat_version; 186 bool allow_glsl_compat_shaders; 187 bool glsl_ignore_write_to_readonly_var; 188 bool glsl_zero_init; 189 bool vs_position_always_invariant; 190 bool vs_position_always_precise; 191 bool force_glsl_abs_sqrt; 192 bool allow_glsl_cross_stage_interpolation_mismatch; 193 bool do_dce_before_clip_cull_analysis; 194 bool allow_draw_out_of_order; 195 bool glthread_nop_check_framebuffer_status; 196 bool ignore_map_unsynchronized; 197 bool ignore_discard_framebuffer; 198 bool force_integer_tex_nearest; 199 bool force_gl_names_reuse; 200 bool force_gl_map_buffer_synchronized; 201 bool transcode_etc; 202 bool transcode_astc; 203 char *force_gl_vendor; 204 char *force_gl_renderer; 205 char *mesa_extension_override; 206 bool allow_multisampled_copyteximage; 207 208 unsigned char config_options_sha1[20]; 209 }; 210 211 struct pipe_frontend_screen; 212 213 /** 214 * Represent a windowing system drawable. 215 * 216 * This is inherited by the drawable implementation of the DRI/GLX/WGL 217 * frontends, e.g. this is the first field in dri_drawable. 218 * 219 * st_context uses the callbacks to invoke one of the DRI/GLX/WGL-specific 220 * functions. 221 * 222 * This drawable can be shared between different threads. The atomic stamp 223 * is used to communicate that the drawable has been changed, and 224 * the framebuffer state should be updated. 225 */ 226 struct pipe_frontend_drawable 227 { 228 /** 229 * Atomic stamp which changes when framebuffers need to be updated. 230 */ 231 int32_t stamp; 232 233 /** 234 * Identifier that uniquely identifies the framebuffer interface object. 235 */ 236 uint32_t ID; 237 238 /** 239 * The frontend screen for DRI/GLX/WGL. This is e.g. dri_screen. 240 */ 241 struct pipe_frontend_screen *fscreen; 242 243 /** 244 * The visual of the framebuffer. 245 */ 246 const struct st_visual *visual; 247 248 /** 249 * Flush the front buffer. 250 * 251 * On some window systems, changes to the front buffers are not immediately 252 * visible. They need to be flushed. 253 * 254 * @att is one of the front buffer attachments. 255 */ 256 bool (*flush_front)(struct st_context *st, 257 struct pipe_frontend_drawable *drawable, 258 enum st_attachment_type statt); 259 260 /** 261 * The GL frontend asks for the framebuffer attachments it needs. 262 * 263 * It should try to only ask for attachments that it currently renders 264 * to, thus allowing the winsys to delay the allocation of textures not 265 * needed. For example front buffer attachments are not needed if you 266 * only do back buffer rendering. 267 * 268 * The implementor of this function needs to also ensure 269 * thread safty as this call might be done from multiple threads. 270 * 271 * The returned textures are owned by the caller. They should be 272 * unreferenced when no longer used. If this function is called multiple 273 * times with different sets of attachments, those buffers not included in 274 * the last call might be destroyed. 275 */ 276 bool (*validate)(struct st_context *st, 277 struct pipe_frontend_drawable *drawable, 278 const enum st_attachment_type *statts, 279 unsigned count, 280 struct pipe_resource **out, 281 struct pipe_resource **resolve); 282 283 bool (*flush_swapbuffers)(struct st_context *st, 284 struct pipe_frontend_drawable *drawable); 285 }; 286 287 288 /** 289 * This is inherited by a screen in the DRI/GLX/WGL frontends, e.g. dri_screen. 290 */ 291 struct pipe_frontend_screen 292 { 293 struct pipe_screen *screen; 294 295 /** 296 * Look up and return the info of an EGLImage. 297 * 298 * This is used to implement for example EGLImageTargetTexture2DOES. 299 * The GLeglImageOES agrument of that call is passed directly to this 300 * function call and the information needed to access this is returned 301 * in the given struct out. 302 * 303 * @fscreen: the screen 304 * @egl_image: EGLImage that caller recived 305 * @out: return struct filled out with access information. 306 * 307 * This function is optional. 308 */ 309 bool (*get_egl_image)(struct pipe_frontend_screen *fscreen, 310 void *egl_image, 311 struct st_egl_image *out); 312 313 /** 314 * Validate EGLImage passed to get_egl_image. 315 */ 316 bool (*validate_egl_image)(struct pipe_frontend_screen *fscreen, 317 void *egl_image); 318 319 /** 320 * Query a feature or property from the DRI/GLX/WGL frontend. 321 */ 322 int (*get_param)(struct pipe_frontend_screen *fscreen, 323 enum st_manager_param param); 324 325 /** 326 * Call the loader function setBackgroundContext. Called from the worker 327 * thread. 328 */ 329 void (*set_background_context)(struct st_context *st, 330 struct util_queue_monitoring *queue_info); 331 332 /** 333 * GL frontend state associated with the screen. 334 * 335 * This is where st_context stores the state shared by all contexts. 336 */ 337 void *st_screen; 338 }; 339 340 #endif /* _API_H_ */ 341