texobj: add verbose api trace messages to several routines
[mesa.git] / src / mesa / main / version.c
1 /*
2 * Mesa 3-D graphics library
3 *
4 * Copyright (C) 2010 VMware, Inc. All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
20 * AN 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 SOFTWARE.
22 */
23
24
25 #include "imports.h"
26 #include "mtypes.h"
27 #include "version.h"
28 #include "git_sha1.h"
29
30 /**
31 * Scans 'string' to see if it ends with 'ending'.
32 */
33 static GLboolean
34 check_for_ending(const char *string, const char *ending)
35 {
36 int len1, len2;
37
38 len1 = strlen(string);
39 len2 = strlen(ending);
40
41 if (len2 > len1) {
42 return GL_FALSE;
43 }
44
45 if (strcmp(string + (len1 - len2), ending) == 0) {
46 return GL_TRUE;
47 } else {
48 return GL_FALSE;
49 }
50 }
51
52 /**
53 * Builds the MESA version string.
54 */
55 static void
56 create_version_string(struct gl_context *ctx, const char *prefix)
57 {
58 static const int max = 100;
59
60 ctx->VersionString = malloc(max);
61 if (ctx->VersionString) {
62 _mesa_snprintf(ctx->VersionString, max,
63 "%s%u.%u%s Mesa " MESA_VERSION_STRING
64 #ifdef MESA_GIT_SHA1
65 " (" MESA_GIT_SHA1 ")"
66 #endif
67 ,
68 prefix,
69 ctx->Version / 10, ctx->Version % 10,
70 (ctx->API == API_OPENGL_CORE) ? " (Core Profile)" : ""
71 );
72 }
73 }
74
75 /**
76 * Override the context's version and/or API type if the
77 * environment variable MESA_GL_VERSION_OVERRIDE is set.
78 *
79 * Example uses of MESA_GL_VERSION_OVERRIDE:
80 *
81 * 2.1: select a compatibility (non-Core) profile with GL version 2.1
82 * 3.0: select a compatibility (non-Core) profile with GL version 3.0
83 * 3.0FC: select a Core+Forward Compatible profile with GL version 3.0
84 * 3.1: select a Core profile with GL version 3.1
85 * 3.1FC: select a Core+Forward Compatible profile with GL version 3.1
86 */
87 void
88 _mesa_override_gl_version(struct gl_context *ctx)
89 {
90 const char *env_var = "MESA_GL_VERSION_OVERRIDE";
91 const char *version;
92 int n;
93 int major, minor;
94 GLboolean fc_suffix;
95
96 version = getenv(env_var);
97 if (!version) {
98 return;
99 }
100
101 fc_suffix = check_for_ending(version, "FC");
102
103 n = sscanf(version, "%u.%u", &major, &minor);
104 if (n != 2) {
105 fprintf(stderr, "error: invalid value for %s: %s\n", env_var, version);
106 } else {
107 ctx->Version = major * 10 + minor;
108 if (ctx->Version < 30 && fc_suffix) {
109 fprintf(stderr, "error: invalid value for %s: %s\n", env_var, version);
110 } else {
111 if (ctx->Version >= 30 && fc_suffix) {
112 ctx->API = API_OPENGL_CORE;
113 ctx->Const.ContextFlags |= GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT;
114 } else if (ctx->Version >= 31) {
115 ctx->API = API_OPENGL_CORE;
116 } else {
117 ctx->API = API_OPENGL_COMPAT;
118 }
119 create_version_string(ctx, "");
120 }
121 }
122 }
123
124 /**
125 * Override the context's GLSL version if the environment variable
126 * MESA_GLSL_VERSION_OVERRIDE is set. Valid values for
127 * MESA_GLSL_VERSION_OVERRIDE are integers, such as "130".
128 */
129 void
130 _mesa_override_glsl_version(struct gl_context *ctx)
131 {
132 const char *env_var = "MESA_GLSL_VERSION_OVERRIDE";
133 const char *version;
134 int n;
135
136 version = getenv(env_var);
137 if (!version) {
138 return;
139 }
140
141 n = sscanf(version, "%u", &ctx->Const.GLSLVersion);
142 if (n != 1) {
143 fprintf(stderr, "error: invalid value for %s: %s\n", env_var, version);
144 return;
145 }
146 }
147
148 /**
149 * Examine enabled GL extensions to determine GL version.
150 */
151 static void
152 compute_version(struct gl_context *ctx)
153 {
154 GLuint major, minor;
155
156 const GLboolean ver_1_3 = (ctx->Extensions.ARB_texture_border_clamp &&
157 ctx->Extensions.ARB_texture_cube_map &&
158 ctx->Extensions.ARB_texture_env_combine &&
159 ctx->Extensions.ARB_texture_env_dot3);
160 const GLboolean ver_1_4 = (ver_1_3 &&
161 ctx->Extensions.ARB_depth_texture &&
162 ctx->Extensions.ARB_shadow &&
163 ctx->Extensions.ARB_texture_env_crossbar &&
164 ctx->Extensions.EXT_blend_color &&
165 ctx->Extensions.EXT_blend_func_separate &&
166 ctx->Extensions.EXT_blend_minmax &&
167 ctx->Extensions.EXT_fog_coord &&
168 ctx->Extensions.EXT_point_parameters &&
169 ctx->Extensions.EXT_secondary_color);
170 const GLboolean ver_1_5 = (ver_1_4 &&
171 ctx->Extensions.ARB_occlusion_query &&
172 ctx->Extensions.EXT_shadow_funcs);
173 const GLboolean ver_2_0 = (ver_1_5 &&
174 ctx->Extensions.ARB_point_sprite &&
175 ctx->Extensions.ARB_shader_objects &&
176 ctx->Extensions.ARB_vertex_shader &&
177 ctx->Extensions.ARB_fragment_shader &&
178 ctx->Extensions.ARB_texture_non_power_of_two &&
179 ctx->Extensions.EXT_blend_equation_separate &&
180
181 /* Technically, 2.0 requires the functionality
182 * of the EXT version. Enable 2.0 if either
183 * extension is available, and assume that a
184 * driver that only exposes the ATI extension
185 * will fallback to software when necessary.
186 */
187 (ctx->Extensions.EXT_stencil_two_side
188 || ctx->Extensions.ATI_separate_stencil));
189 const GLboolean ver_2_1 = (ver_2_0 &&
190 ctx->Const.GLSLVersion >= 120 &&
191 ctx->Extensions.EXT_pixel_buffer_object &&
192 ctx->Extensions.EXT_texture_sRGB);
193 const GLboolean ver_3_0 = (ver_2_1 &&
194 ctx->Const.GLSLVersion >= 130 &&
195 ctx->Const.MaxSamples >= 4 &&
196 ctx->Extensions.ARB_color_buffer_float &&
197 ctx->Extensions.ARB_depth_buffer_float &&
198 ctx->Extensions.ARB_half_float_pixel &&
199 ctx->Extensions.ARB_half_float_vertex &&
200 ctx->Extensions.ARB_map_buffer_range &&
201 ctx->Extensions.ARB_shader_texture_lod &&
202 ctx->Extensions.ARB_texture_float &&
203 ctx->Extensions.ARB_texture_rg &&
204 ctx->Extensions.ARB_texture_compression_rgtc &&
205 ctx->Extensions.EXT_draw_buffers2 &&
206 ctx->Extensions.ARB_framebuffer_object &&
207 ctx->Extensions.EXT_framebuffer_sRGB &&
208 ctx->Extensions.EXT_packed_float &&
209 ctx->Extensions.EXT_texture_array &&
210 ctx->Extensions.EXT_texture_shared_exponent &&
211 ctx->Extensions.EXT_transform_feedback &&
212 ctx->Extensions.NV_conditional_render);
213 const GLboolean ver_3_1 = (ver_3_0 &&
214 ctx->Const.GLSLVersion >= 140 &&
215 ctx->Extensions.ARB_draw_instanced &&
216 ctx->Extensions.ARB_texture_buffer_object &&
217 ctx->Extensions.ARB_uniform_buffer_object &&
218 ctx->Extensions.EXT_texture_snorm &&
219 ctx->Extensions.NV_primitive_restart &&
220 ctx->Extensions.NV_texture_rectangle &&
221 ctx->Const.MaxVertexTextureImageUnits >= 16);
222 const GLboolean ver_3_2 = (ver_3_1 &&
223 ctx->Const.GLSLVersion >= 150 &&
224 ctx->Extensions.ARB_depth_clamp &&
225 ctx->Extensions.ARB_draw_elements_base_vertex &&
226 ctx->Extensions.ARB_fragment_coord_conventions &&
227 ctx->Extensions.ARB_geometry_shader4 &&
228 ctx->Extensions.EXT_provoking_vertex &&
229 ctx->Extensions.ARB_seamless_cube_map &&
230 ctx->Extensions.ARB_sync &&
231 ctx->Extensions.ARB_texture_multisample &&
232 ctx->Extensions.EXT_vertex_array_bgra);
233 const GLboolean ver_3_3 = (ver_3_2 &&
234 ctx->Const.GLSLVersion >= 330 &&
235 ctx->Extensions.ARB_blend_func_extended &&
236 ctx->Extensions.ARB_explicit_attrib_location &&
237 ctx->Extensions.ARB_instanced_arrays &&
238 ctx->Extensions.ARB_occlusion_query2 &&
239 ctx->Extensions.ARB_shader_bit_encoding &&
240 ctx->Extensions.ARB_texture_rgb10_a2ui &&
241 ctx->Extensions.ARB_timer_query &&
242 ctx->Extensions.ARB_vertex_type_2_10_10_10_rev &&
243 ctx->Extensions.EXT_texture_swizzle);
244 /* ARB_sampler_objects is always enabled in mesa */
245
246 if (ver_3_3) {
247 major = 3;
248 minor = 3;
249 }
250 else if (ver_3_2) {
251 major = 3;
252 minor = 2;
253 }
254 else if (ver_3_1) {
255 major = 3;
256 minor = 1;
257 }
258 else if (ver_3_0) {
259 major = 3;
260 minor = 0;
261 }
262 else if (ver_2_1) {
263 major = 2;
264 minor = 1;
265 }
266 else if (ver_2_0) {
267 major = 2;
268 minor = 0;
269 }
270 else if (ver_1_5) {
271 major = 1;
272 minor = 5;
273 }
274 else if (ver_1_4) {
275 major = 1;
276 minor = 4;
277 }
278 else if (ver_1_3) {
279 major = 1;
280 minor = 3;
281 }
282 else {
283 major = 1;
284 minor = 2;
285 }
286
287 ctx->Version = major * 10 + minor;
288
289 create_version_string(ctx, "");
290 }
291
292 static void
293 compute_version_es1(struct gl_context *ctx)
294 {
295 /* OpenGL ES 1.0 is derived from OpenGL 1.3 */
296 const GLboolean ver_1_0 = (ctx->Extensions.ARB_texture_env_combine &&
297 ctx->Extensions.ARB_texture_env_dot3);
298 /* OpenGL ES 1.1 is derived from OpenGL 1.5 */
299 const GLboolean ver_1_1 = (ver_1_0 &&
300 ctx->Extensions.EXT_point_parameters);
301
302 if (ver_1_1) {
303 ctx->Version = 11;
304 } else if (ver_1_0) {
305 ctx->Version = 10;
306 } else {
307 _mesa_problem(ctx, "Incomplete OpenGL ES 1.0 support.");
308 }
309
310 create_version_string(ctx, "OpenGL ES-CM ");
311 }
312
313 static void
314 compute_version_es2(struct gl_context *ctx)
315 {
316 /* OpenGL ES 2.0 is derived from OpenGL 2.0 */
317 const GLboolean ver_2_0 = (ctx->Extensions.ARB_texture_cube_map &&
318 ctx->Extensions.EXT_blend_color &&
319 ctx->Extensions.EXT_blend_func_separate &&
320 ctx->Extensions.EXT_blend_minmax &&
321 ctx->Extensions.ARB_shader_objects &&
322 ctx->Extensions.ARB_vertex_shader &&
323 ctx->Extensions.ARB_fragment_shader &&
324 ctx->Extensions.ARB_texture_non_power_of_two &&
325 ctx->Extensions.EXT_blend_equation_separate);
326 /* FINISHME: This list isn't quite right. */
327 const GLboolean ver_3_0 = (ctx->Extensions.ARB_half_float_vertex &&
328 ctx->Extensions.ARB_internalformat_query &&
329 ctx->Extensions.ARB_map_buffer_range &&
330 ctx->Extensions.ARB_shader_texture_lod &&
331 ctx->Extensions.ARB_texture_float &&
332 ctx->Extensions.ARB_texture_rg &&
333 ctx->Extensions.ARB_texture_compression_rgtc &&
334 ctx->Extensions.EXT_draw_buffers2 &&
335 /* ctx->Extensions.ARB_framebuffer_object && */
336 ctx->Extensions.EXT_framebuffer_sRGB &&
337 ctx->Extensions.EXT_packed_float &&
338 ctx->Extensions.EXT_texture_array &&
339 ctx->Extensions.EXT_texture_shared_exponent &&
340 ctx->Extensions.EXT_transform_feedback &&
341 ctx->Extensions.NV_conditional_render &&
342 ctx->Extensions.ARB_draw_instanced &&
343 ctx->Extensions.ARB_uniform_buffer_object &&
344 ctx->Extensions.EXT_texture_snorm &&
345 ctx->Extensions.NV_primitive_restart &&
346 ctx->Extensions.OES_depth_texture_cube_map);
347 if (ver_3_0) {
348 ctx->Version = 30;
349 } else if (ver_2_0) {
350 ctx->Version = 20;
351 } else {
352 _mesa_problem(ctx, "Incomplete OpenGL ES 2.0 support.");
353 }
354
355 create_version_string(ctx, "OpenGL ES ");
356 }
357
358 /**
359 * Set the context's Version and VersionString fields.
360 * This should only be called once as part of context initialization
361 * or to perform version check for GLX_ARB_create_context_profile.
362 */
363 void
364 _mesa_compute_version(struct gl_context *ctx)
365 {
366 if (ctx->Version)
367 return;
368
369 switch (ctx->API) {
370 case API_OPENGL_COMPAT:
371 /* Disable GLSL 1.40 and later for legacy contexts.
372 * This disallows creation of the GL 3.1 compatibility context. */
373 if (ctx->Const.GLSLVersion > 130) {
374 ctx->Const.GLSLVersion = 130;
375 }
376 /* fall through */
377 case API_OPENGL_CORE:
378 compute_version(ctx);
379 break;
380 case API_OPENGLES:
381 compute_version_es1(ctx);
382 break;
383 case API_OPENGLES2:
384 compute_version_es2(ctx);
385 break;
386 }
387
388 }