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 int reuse_gl_names; 200 bool force_gl_map_buffer_synchronized; 201 bool transcode_etc; 202 bool transcode_astc; 203 bool allow_compressed_fallback; 204 char *force_gl_vendor; 205 char *force_gl_renderer; 206 char *mesa_extension_override; 207 bool allow_multisampled_copyteximage; 208 209 unsigned char config_options_sha1[20]; 210 }; 211 212 struct pipe_frontend_screen; 213 214 /** 215 * Represent a windowing system drawable. 216 * 217 * This is inherited by the drawable implementation of the DRI/GLX/WGL 218 * frontends, e.g. this is the first field in dri_drawable. 219 * 220 * st_context uses the callbacks to invoke one of the DRI/GLX/WGL-specific 221 * functions. 222 * 223 * This drawable can be shared between different threads. The atomic stamp 224 * is used to communicate that the drawable has been changed, and 225 * the framebuffer state should be updated. 226 */ 227 struct pipe_frontend_drawable 228 { 229 /** 230 * Atomic stamp which changes when framebuffers need to be updated. 231 */ 232 int32_t stamp; 233 234 /** 235 * Identifier that uniquely identifies the framebuffer interface object. 236 */ 237 uint32_t ID; 238 239 /** 240 * The frontend screen for DRI/GLX/WGL. This is e.g. dri_screen. 241 */ 242 struct pipe_frontend_screen *fscreen; 243 244 /** 245 * The visual of the framebuffer. 246 */ 247 const struct st_visual *visual; 248 249 /** 250 * Flush the front buffer. 251 * 252 * On some window systems, changes to the front buffers are not immediately 253 * visible. They need to be flushed. 254 * 255 * @att is one of the front buffer attachments. 256 */ 257 bool (*flush_front)(struct st_context *st, 258 struct pipe_frontend_drawable *drawable, 259 enum st_attachment_type statt); 260 261 /** 262 * The GL frontend asks for the framebuffer attachments it needs. 263 * 264 * It should try to only ask for attachments that it currently renders 265 * to, thus allowing the winsys to delay the allocation of textures not 266 * needed. For example front buffer attachments are not needed if you 267 * only do back buffer rendering. 268 * 269 * The implementor of this function needs to also ensure 270 * thread safty as this call might be done from multiple threads. 271 * 272 * The returned textures are owned by the caller. They should be 273 * unreferenced when no longer used. If this function is called multiple 274 * times with different sets of attachments, those buffers not included in 275 * the last call might be destroyed. 276 */ 277 bool (*validate)(struct st_context *st, 278 struct pipe_frontend_drawable *drawable, 279 const enum st_attachment_type *statts, 280 unsigned count, 281 struct pipe_resource **out, 282 struct pipe_resource **resolve); 283 284 bool (*flush_swapbuffers)(struct st_context *st, 285 struct pipe_frontend_drawable *drawable); 286 }; 287 288 289 /** 290 * This is inherited by a screen in the DRI/GLX/WGL frontends, e.g. dri_screen. 291 */ 292 struct pipe_frontend_screen 293 { 294 struct pipe_screen *screen; 295 296 /** 297 * Look up and return the info of an EGLImage. 298 * 299 * This is used to implement for example EGLImageTargetTexture2DOES. 300 * The GLeglImageOES agrument of that call is passed directly to this 301 * function call and the information needed to access this is returned 302 * in the given struct out. 303 * 304 * @fscreen: the screen 305 * @egl_image: EGLImage that caller recived 306 * @out: return struct filled out with access information. 307 * 308 * This function is optional. 309 */ 310 bool (*get_egl_image)(struct pipe_frontend_screen *fscreen, 311 void *egl_image, 312 struct st_egl_image *out); 313 314 /** 315 * Validate EGLImage passed to get_egl_image. 316 */ 317 bool (*validate_egl_image)(struct pipe_frontend_screen *fscreen, 318 void *egl_image); 319 320 /** 321 * Query a feature or property from the DRI/GLX/WGL frontend. 322 */ 323 int (*get_param)(struct pipe_frontend_screen *fscreen, 324 enum st_manager_param param); 325 326 /** 327 * Call the loader function setBackgroundContext. Called from the worker 328 * thread. 329 */ 330 void (*set_background_context)(struct st_context *st, 331 struct util_queue_monitoring *queue_info); 332 333 /** 334 * GL frontend state associated with the screen. 335 * 336 * This is where st_context stores the state shared by all contexts. 337 */ 338 void *st_screen; 339 }; 340 341 #endif /* _API_H_ */ 342