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 OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25
26 #include <stdio.h>
27 #include "context.h"
28 #include "draw_validate.h"
29
30 #include "util/os_misc.h"
31 #include "util/simple_mtx.h"
32
33 #include "mtypes.h"
34 #include "version.h"
35 #include "git_sha1.h"
36
37 #include "state_tracker/st_context.h"
38
39 static simple_mtx_t override_lock = SIMPLE_MTX_INITIALIZER;
40
41 /**
42 * Scans 'string' to see if it ends with 'ending'.
43 */
44 static bool
check_for_ending(const char * string,const char * ending)45 check_for_ending(const char *string, const char *ending)
46 {
47 const size_t len1 = strlen(string);
48 const size_t len2 = strlen(ending);
49
50 if (len2 > len1)
51 return false;
52
53 return strcmp(string + (len1 - len2), ending) == 0;
54 }
55
56 /**
57 * Returns the gl override data
58 *
59 * version > 0 indicates there is an override requested
60 * fwd_context is only valid if version > 0
61 */
62 static void
get_gl_override(gl_api api,int * version,bool * fwd_context,bool * compat_context)63 get_gl_override(gl_api api, int *version, bool *fwd_context,
64 bool *compat_context)
65 {
66 const char *env_var = (api == API_OPENGL_CORE || api == API_OPENGL_COMPAT)
67 ? "MESA_GL_VERSION_OVERRIDE" : "MESA_GLES_VERSION_OVERRIDE";
68 const char *version_str;
69 int major, minor, n;
70 static struct override_info {
71 int version;
72 bool fc_suffix;
73 bool compat_suffix;
74 } override[] = {
75 [API_OPENGL_COMPAT] = { -1, false, false},
76 [API_OPENGLES] = { -1, false, false},
77 [API_OPENGLES2] = { -1, false, false},
78 [API_OPENGL_CORE] = { -1, false, false},
79 };
80
81 STATIC_ASSERT(ARRAY_SIZE(override) == API_OPENGL_LAST + 1);
82
83 simple_mtx_lock(&override_lock);
84
85 if (api == API_OPENGLES)
86 goto exit;
87
88 if (override[api].version < 0) {
89 override[api].version = 0;
90
91 version_str = os_get_option(env_var);
92 if (version_str) {
93 override[api].fc_suffix = check_for_ending(version_str, "FC");
94 override[api].compat_suffix = check_for_ending(version_str, "COMPAT");
95
96 n = sscanf(version_str, "%u.%u", &major, &minor);
97 if (n != 2) {
98 fprintf(stderr, "error: invalid value for %s: %s\n",
99 env_var, version_str);
100 override[api].version = 0;
101 } else {
102 override[api].version = major * 10 + minor;
103
104 /* There is no such thing as compatibility or forward-compatible for
105 * OpenGL ES 2.0 or 3.x APIs.
106 */
107 if ((override[api].version < 30 && override[api].fc_suffix) ||
108 (api == API_OPENGLES2 && (override[api].fc_suffix ||
109 override[api].compat_suffix))) {
110 fprintf(stderr, "error: invalid value for %s: %s\n",
111 env_var, version_str);
112 }
113 }
114 }
115 }
116
117 exit:
118 *version = override[api].version;
119 *fwd_context = override[api].fc_suffix;
120 *compat_context = override[api].compat_suffix;
121
122 simple_mtx_unlock(&override_lock);
123 }
124
125 /**
126 * Builds the Mesa version string.
127 */
128 static void
create_version_string(struct gl_context * ctx,const char * prefix)129 create_version_string(struct gl_context *ctx, const char *prefix)
130 {
131 static const int max = 100;
132
133 ctx->VersionString = malloc(max);
134 if (ctx->VersionString) {
135 snprintf(ctx->VersionString, max,
136 "%s%u.%u%s Mesa " PACKAGE_VERSION MESA_GIT_SHA1,
137 prefix,
138 ctx->Version / 10, ctx->Version % 10,
139 _mesa_is_desktop_gl_core(ctx) ? " (Core Profile)" :
140 (_mesa_is_desktop_gl_compat(ctx) && ctx->Version >= 32) ?
141 " (Compatibility Profile)" : ""
142 );
143 }
144 }
145
146 /**
147 * Override the context's version and/or API type if the environment variables
148 * MESA_GL_VERSION_OVERRIDE or MESA_GLES_VERSION_OVERRIDE are set.
149 *
150 * Example uses of MESA_GL_VERSION_OVERRIDE:
151 *
152 * 2.1: select a compatibility (non-Core) profile with GL version 2.1.
153 * 3.0: select a compatibility (non-Core) profile with GL version 3.0.
154 * 3.0FC: select a Core+Forward Compatible profile with GL version 3.0.
155 * 3.1: select GL version 3.1 with GL_ARB_compatibility enabled per the driver default.
156 * 3.1FC: select GL version 3.1 with forward compatibility and GL_ARB_compatibility disabled.
157 * 3.1COMPAT: select GL version 3.1 with GL_ARB_compatibility enabled.
158 * X.Y: override GL version to X.Y without changing the profile.
159 * X.YFC: select a Core+Forward Compatible profile with GL version X.Y.
160 * X.YCOMPAT: select a Compatibility profile with GL version X.Y.
161 *
162 * Example uses of MESA_GLES_VERSION_OVERRIDE:
163 *
164 * 2.0: select GLES version 2.0.
165 * 3.0: select GLES version 3.0.
166 * 3.1: select GLES version 3.1.
167 */
168 bool
_mesa_override_gl_version_contextless(struct gl_constants * consts,gl_api * apiOut,GLuint * versionOut)169 _mesa_override_gl_version_contextless(struct gl_constants *consts,
170 gl_api *apiOut, GLuint *versionOut)
171 {
172 int version;
173 bool fwd_context, compat_context;
174
175 get_gl_override(*apiOut, &version, &fwd_context, &compat_context);
176
177 if (version > 0) {
178 *versionOut = version;
179
180 /* Modify the API and context flags as needed. */
181 if (*apiOut == API_OPENGL_CORE || *apiOut == API_OPENGL_COMPAT) {
182 if (version >= 30 && fwd_context) {
183 *apiOut = API_OPENGL_CORE;
184 consts->ContextFlags |= GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT;
185 } else if (compat_context) {
186 *apiOut = API_OPENGL_COMPAT;
187 }
188 }
189
190 return true;
191 }
192 return false;
193 }
194
195 void
_mesa_override_gl_version(struct gl_context * ctx)196 _mesa_override_gl_version(struct gl_context *ctx)
197 {
198 if (_mesa_override_gl_version_contextless(&ctx->Const, &ctx->API,
199 &ctx->Version)) {
200 /* We need to include API in version string for OpenGL ES, otherwise
201 * application can not detect GLES via glGetString(GL_VERSION) query.
202 *
203 * From OpenGL ES 3.2 spec, Page 436:
204 *
205 * "The VERSION string is laid out as follows:
206 *
207 * OpenGL ES N.M vendor-specific information"
208 *
209 * From OpenGL 4.5 spec, Page 538:
210 *
211 * "The VERSION and SHADING_LANGUAGE_VERSION strings are laid out as
212 * follows:
213 *
214 * <version number><space><vendor-specific information>"
215 */
216 create_version_string(ctx, _mesa_is_gles(ctx) ? "OpenGL ES " : "");
217 ctx->Extensions.Version = ctx->Version;
218 }
219 }
220
221 /**
222 * Override the context's GLSL version if the environment variable
223 * MESA_GLSL_VERSION_OVERRIDE is set. Valid values for
224 * MESA_GLSL_VERSION_OVERRIDE are integers, such as "130".
225 */
226 void
_mesa_override_glsl_version(struct gl_constants * consts)227 _mesa_override_glsl_version(struct gl_constants *consts)
228 {
229 const char *env_var = "MESA_GLSL_VERSION_OVERRIDE";
230 const char *version;
231 int n;
232
233 version = getenv(env_var);
234 if (!version) {
235 return;
236 }
237
238 n = sscanf(version, "%u", &consts->GLSLVersion);
239 if (n != 1) {
240 fprintf(stderr, "error: invalid value for %s: %s\n", env_var, version);
241 return;
242 }
243 }
244
245 /**
246 * Examine enabled GL extensions to determine GL version.
247 */
248 static GLuint
compute_version(const struct gl_extensions * extensions,const struct gl_constants * consts,gl_api api)249 compute_version(const struct gl_extensions *extensions,
250 const struct gl_constants *consts, gl_api api)
251 {
252 GLuint major, minor, version;
253
254 const bool ver_1_4 = (extensions->ARB_shadow);
255 const bool ver_1_5 = ver_1_4;
256 const bool ver_2_0 = (ver_1_5 &&
257 extensions->ARB_vertex_shader &&
258 extensions->ARB_fragment_shader &&
259 extensions->ARB_texture_non_power_of_two &&
260 extensions->EXT_blend_equation_separate &&
261 extensions->EXT_stencil_two_side);
262 const bool ver_2_1 = (ver_2_0 &&
263 extensions->EXT_texture_sRGB);
264 /* We lie about the minimum number of color attachments. Strictly, OpenGL
265 * 3.0 requires 8, whereas OpenGL ES requires 4. OpenGL ES 3.0 class
266 * hardware may only support 4 render targets. Advertise non-conformant
267 * OpenGL 3.0 anyway. Affects freedreno on a3xx
268 */
269 const bool ver_3_0 = (ver_2_1 &&
270 consts->GLSLVersion >= 130 &&
271 consts->MaxColorAttachments >= 4 &&
272 (consts->MaxSamples >= 4 || consts->FakeSWMSAA) &&
273 (api == API_OPENGL_CORE ||
274 extensions->ARB_color_buffer_float) &&
275 extensions->ARB_depth_buffer_float &&
276 extensions->ARB_half_float_vertex &&
277 extensions->ARB_map_buffer_range &&
278 extensions->ARB_shader_texture_lod &&
279 extensions->ARB_texture_float &&
280 extensions->ARB_texture_rg &&
281 extensions->ARB_texture_compression_rgtc &&
282 extensions->EXT_draw_buffers2 &&
283 extensions->ARB_framebuffer_object &&
284 extensions->EXT_framebuffer_sRGB &&
285 extensions->EXT_packed_float &&
286 extensions->EXT_texture_array &&
287 extensions->EXT_texture_integer &&
288 extensions->EXT_texture_shared_exponent &&
289 extensions->EXT_transform_feedback &&
290 extensions->NV_conditional_render);
291 const bool ver_3_1 = (ver_3_0 &&
292 consts->GLSLVersion >= 140 &&
293 extensions->ARB_draw_instanced &&
294 extensions->ARB_texture_buffer_object &&
295 extensions->ARB_uniform_buffer_object &&
296 extensions->EXT_texture_snorm &&
297 extensions->NV_primitive_restart &&
298 extensions->NV_texture_rectangle &&
299 consts->Program[MESA_SHADER_VERTEX].MaxTextureImageUnits >= 16);
300 const bool ver_3_2 = (ver_3_1 &&
301 consts->GLSLVersion >= 150 &&
302 extensions->ARB_depth_clamp &&
303 extensions->ARB_draw_elements_base_vertex &&
304 extensions->ARB_fragment_coord_conventions &&
305 extensions->EXT_provoking_vertex &&
306 extensions->ARB_seamless_cube_map &&
307 extensions->ARB_sync &&
308 extensions->ARB_texture_multisample &&
309 extensions->EXT_vertex_array_bgra);
310 const bool ver_3_3 = (ver_3_2 &&
311 consts->GLSLVersion >= 330 &&
312 extensions->ARB_blend_func_extended &&
313 extensions->ARB_explicit_attrib_location &&
314 extensions->ARB_instanced_arrays &&
315 extensions->ARB_shader_bit_encoding &&
316 extensions->ARB_texture_rgb10_a2ui &&
317 extensions->ARB_timer_query &&
318 extensions->ARB_vertex_type_2_10_10_10_rev &&
319 extensions->EXT_texture_swizzle);
320 /* ARB_sampler_objects is always enabled in mesa */
321
322 const bool ver_4_0 = (ver_3_3 &&
323 consts->GLSLVersion >= 400 &&
324 extensions->ARB_draw_buffers_blend &&
325 extensions->ARB_draw_indirect &&
326 extensions->ARB_gpu_shader5 &&
327 extensions->ARB_gpu_shader_fp64 &&
328 extensions->ARB_sample_shading &&
329 extensions->ARB_tessellation_shader &&
330 extensions->ARB_texture_buffer_object_rgb32 &&
331 extensions->ARB_texture_cube_map_array &&
332 extensions->ARB_texture_query_lod &&
333 extensions->ARB_transform_feedback2 &&
334 extensions->ARB_transform_feedback3);
335 const bool ver_4_1 = (ver_4_0 &&
336 consts->GLSLVersion >= 410 &&
337 consts->MaxTextureSize >= 16384 &&
338 consts->MaxRenderbufferSize >= 16384 &&
339 consts->MaxCubeTextureLevels >= 15 &&
340 consts->Max3DTextureLevels >= 12 &&
341 consts->MaxArrayTextureLayers >= 2048 &&
342 extensions->ARB_ES2_compatibility &&
343 extensions->ARB_shader_precision &&
344 extensions->ARB_vertex_attrib_64bit &&
345 extensions->ARB_viewport_array);
346 const bool ver_4_2 = (ver_4_1 &&
347 consts->GLSLVersion >= 420 &&
348 extensions->ARB_base_instance &&
349 extensions->ARB_conservative_depth &&
350 extensions->ARB_internalformat_query &&
351 extensions->ARB_shader_atomic_counters &&
352 extensions->ARB_shader_image_load_store &&
353 extensions->ARB_shading_language_420pack &&
354 extensions->ARB_shading_language_packing &&
355 extensions->ARB_texture_compression_bptc &&
356 extensions->ARB_transform_feedback_instanced);
357 const bool ver_4_3 = (ver_4_2 &&
358 consts->GLSLVersion >= 430 &&
359 consts->Program[MESA_SHADER_VERTEX].MaxUniformBlocks >= 14 &&
360 extensions->ARB_ES3_compatibility &&
361 extensions->ARB_arrays_of_arrays &&
362 extensions->ARB_compute_shader &&
363 extensions->ARB_copy_image &&
364 extensions->ARB_explicit_uniform_location &&
365 extensions->ARB_fragment_layer_viewport &&
366 extensions->ARB_framebuffer_no_attachments &&
367 extensions->ARB_internalformat_query2 &&
368 extensions->ARB_robust_buffer_access_behavior &&
369 extensions->ARB_shader_image_size &&
370 extensions->ARB_shader_storage_buffer_object &&
371 extensions->ARB_stencil_texturing &&
372 extensions->ARB_texture_buffer_range &&
373 extensions->ARB_texture_query_levels &&
374 extensions->ARB_texture_view);
375 const bool ver_4_4 = (ver_4_3 &&
376 consts->GLSLVersion >= 440 &&
377 consts->MaxVertexAttribStride >= 2048 &&
378 extensions->ARB_buffer_storage &&
379 extensions->ARB_enhanced_layouts &&
380 extensions->ARB_query_buffer_object &&
381 extensions->ARB_texture_mirror_clamp_to_edge &&
382 extensions->ARB_texture_stencil8 &&
383 extensions->ARB_vertex_type_10f_11f_11f_rev);
384 const bool ver_4_5 = (ver_4_4 &&
385 consts->GLSLVersion >= 450 &&
386 extensions->ARB_ES3_1_compatibility &&
387 extensions->ARB_clip_control &&
388 extensions->ARB_conditional_render_inverted &&
389 extensions->ARB_cull_distance &&
390 extensions->ARB_derivative_control &&
391 extensions->ARB_shader_texture_image_samples &&
392 extensions->NV_texture_barrier);
393 const bool ver_4_6 = (ver_4_5 &&
394 consts->GLSLVersion >= 460 &&
395 extensions->ARB_gl_spirv &&
396 extensions->ARB_spirv_extensions &&
397 extensions->ARB_indirect_parameters &&
398 extensions->ARB_polygon_offset_clamp &&
399 extensions->ARB_shader_atomic_counter_ops &&
400 extensions->ARB_shader_draw_parameters &&
401 extensions->ARB_shader_group_vote &&
402 extensions->ARB_texture_filter_anisotropic &&
403 extensions->ARB_transform_feedback_overflow_query);
404
405 if (ver_4_6) {
406 major = 4;
407 minor = 6;
408 }
409 else if (ver_4_5) {
410 major = 4;
411 minor = 5;
412 }
413 else if (ver_4_4) {
414 major = 4;
415 minor = 4;
416 }
417 else if (ver_4_3) {
418 major = 4;
419 minor = 3;
420 }
421 else if (ver_4_2) {
422 major = 4;
423 minor = 2;
424 }
425 else if (ver_4_1) {
426 major = 4;
427 minor = 1;
428 }
429 else if (ver_4_0) {
430 major = 4;
431 minor = 0;
432 }
433 else if (ver_3_3) {
434 major = 3;
435 minor = 3;
436 }
437 else if (ver_3_2) {
438 major = 3;
439 minor = 2;
440 }
441 else if (ver_3_1) {
442 major = 3;
443 minor = 1;
444 }
445 else if (ver_3_0) {
446 major = 3;
447 minor = 0;
448 }
449 else if (ver_2_1) {
450 major = 2;
451 minor = 1;
452 }
453 else if (ver_2_0) {
454 major = 2;
455 minor = 0;
456 }
457 else if (ver_1_5) {
458 major = 1;
459 minor = 5;
460 }
461 else if (ver_1_4) {
462 major = 1;
463 minor = 4;
464 }
465 else {
466 major = 1;
467 minor = 3;
468 }
469
470 version = major * 10 + minor;
471
472 if (api == API_OPENGL_CORE && version < 31)
473 return 0;
474
475 return version;
476 }
477
478 static GLuint
compute_version_es2(const struct gl_extensions * extensions,const struct gl_constants * consts)479 compute_version_es2(const struct gl_extensions *extensions,
480 const struct gl_constants *consts)
481 {
482 /* OpenGL ES 2.0 is derived from OpenGL 2.0 */
483 const bool ver_2_0 = (extensions->ARB_vertex_shader &&
484 extensions->ARB_fragment_shader &&
485 extensions->ARB_texture_non_power_of_two &&
486 extensions->EXT_blend_equation_separate);
487 /* FINISHME: This list isn't quite right. */
488 const bool ver_3_0 = (extensions->ARB_half_float_vertex &&
489 extensions->ARB_internalformat_query &&
490 extensions->ARB_map_buffer_range &&
491 extensions->ARB_shader_texture_lod &&
492 extensions->OES_texture_float &&
493 extensions->OES_texture_half_float &&
494 extensions->OES_texture_half_float_linear &&
495 extensions->ARB_texture_rg &&
496 extensions->ARB_depth_buffer_float &&
497 extensions->ARB_framebuffer_object &&
498 extensions->EXT_sRGB &&
499 extensions->EXT_packed_float &&
500 extensions->EXT_texture_array &&
501 extensions->EXT_texture_shared_exponent &&
502 extensions->EXT_texture_sRGB &&
503 extensions->EXT_transform_feedback &&
504 extensions->ARB_draw_instanced &&
505 extensions->ARB_instanced_arrays &&
506 extensions->ARB_uniform_buffer_object &&
507 extensions->EXT_texture_snorm &&
508 (extensions->NV_primitive_restart ||
509 consts->PrimitiveRestartFixedIndex) &&
510 extensions->OES_depth_texture_cube_map &&
511 extensions->EXT_texture_type_2_10_10_10_REV &&
512 consts->MaxColorAttachments >= 4);
513 const bool es31_compute_shader =
514 consts->MaxComputeWorkGroupInvocations >= 128 &&
515 consts->Program[MESA_SHADER_COMPUTE].MaxShaderStorageBlocks &&
516 consts->Program[MESA_SHADER_COMPUTE].MaxAtomicBuffers &&
517 consts->Program[MESA_SHADER_COMPUTE].MaxImageUniforms;
518 const bool ver_3_1 = (ver_3_0 &&
519 consts->MaxVertexAttribStride >= 2048 &&
520 extensions->ARB_arrays_of_arrays &&
521 es31_compute_shader &&
522 extensions->ARB_draw_indirect &&
523 extensions->ARB_explicit_uniform_location &&
524 extensions->ARB_framebuffer_no_attachments &&
525 extensions->ARB_shading_language_packing &&
526 extensions->ARB_stencil_texturing &&
527 extensions->ARB_texture_multisample &&
528 extensions->ARB_texture_gather &&
529 extensions->MESA_shader_integer_functions &&
530 extensions->EXT_shader_integer_mix);
531 const bool ver_3_2 = (ver_3_1 &&
532 /* ES 3.2 requires that images/buffers be accessible
533 * from fragment shaders as well
534 */
535 extensions->ARB_shader_atomic_counters &&
536 extensions->ARB_shader_image_load_store &&
537 extensions->ARB_shader_image_size &&
538 extensions->ARB_shader_storage_buffer_object &&
539 extensions->EXT_color_buffer_float &&
540 extensions->EXT_draw_buffers2 &&
541 extensions->KHR_blend_equation_advanced &&
542 extensions->KHR_robustness &&
543 extensions->KHR_texture_compression_astc_ldr &&
544 extensions->OES_copy_image &&
545 extensions->ARB_draw_buffers_blend &&
546 extensions->ARB_draw_elements_base_vertex &&
547 extensions->OES_geometry_shader &&
548 extensions->OES_primitive_bounding_box &&
549 extensions->OES_sample_variables &&
550 extensions->ARB_tessellation_shader &&
551 extensions->OES_texture_buffer &&
552 extensions->OES_texture_cube_map_array &&
553 extensions->ARB_texture_stencil8);
554
555 if (ver_3_2) {
556 return 32;
557 } else if (ver_3_1) {
558 return 31;
559 } else if (ver_3_0) {
560 return 30;
561 } else if (ver_2_0) {
562 return 20;
563 } else {
564 return 0;
565 }
566 }
567
568 GLuint
_mesa_get_version(const struct gl_extensions * extensions,struct gl_constants * consts,gl_api api)569 _mesa_get_version(const struct gl_extensions *extensions,
570 struct gl_constants *consts, gl_api api)
571 {
572 switch (api) {
573 case API_OPENGL_COMPAT:
574 /* Disable higher GLSL versions for legacy contexts.
575 * This disallows creation of higher compatibility contexts. */
576 if (!consts->AllowHigherCompatVersion) {
577 consts->GLSLVersion = consts->GLSLVersionCompat;
578 }
579 FALLTHROUGH;
580 case API_OPENGL_CORE:
581 return compute_version(extensions, consts, api);
582 case API_OPENGLES:
583 return 11;
584 case API_OPENGLES2:
585 return compute_version_es2(extensions, consts);
586 }
587 return 0;
588 }
589
590 /**
591 * Set the context's Version and VersionString fields.
592 * This should only be called once as part of context initialization
593 * or to perform version check for GLX_ARB_create_context_profile.
594 */
595 void
_mesa_compute_version(struct gl_context * ctx)596 _mesa_compute_version(struct gl_context *ctx)
597 {
598 if (ctx->Version)
599 goto done;
600
601 ctx->Version = _mesa_get_version(&ctx->Extensions, &ctx->Const, ctx->API);
602 ctx->Extensions.Version = ctx->Version;
603
604 /* Make sure that the GLSL version lines up with the GL version. In some
605 * cases it can be too high, e.g. if an extension is missing.
606 */
607 if (_mesa_is_desktop_gl(ctx)) {
608 switch (ctx->Version) {
609 case 20:
610 FALLTHROUGH; /* GLSL 1.20 is the minimum we support */
611 case 21:
612 ctx->Const.GLSLVersion = 120;
613 break;
614 case 30:
615 ctx->Const.GLSLVersion = 130;
616 break;
617 case 31:
618 ctx->Const.GLSLVersion = 140;
619 break;
620 case 32:
621 ctx->Const.GLSLVersion = 150;
622 break;
623 default:
624 if (ctx->Version >= 33)
625 ctx->Const.GLSLVersion = ctx->Version * 10;
626 break;
627 }
628 }
629
630 switch (ctx->API) {
631 case API_OPENGL_COMPAT:
632 case API_OPENGL_CORE:
633 create_version_string(ctx, "");
634 break;
635
636 case API_OPENGLES:
637 if (!ctx->Version) {
638 _mesa_problem(ctx, "Incomplete OpenGL ES 1.0 support.");
639 return;
640 }
641 create_version_string(ctx, "OpenGL ES-CM ");
642 break;
643
644 case API_OPENGLES2:
645 if (!ctx->Version) {
646 _mesa_problem(ctx, "Incomplete OpenGL ES 2.0 support.");
647 return;
648 }
649 create_version_string(ctx, "OpenGL ES ");
650 break;
651 }
652
653 done:
654 if (_mesa_is_desktop_gl_compat(ctx) && ctx->Version >= 31)
655 ctx->Extensions.ARB_compatibility = GL_TRUE;
656
657 /* Precompute valid primitive types for faster draw time validation. */
658 /* All primitive type enums are less than 32, so we can use the shift. */
659 ctx->SupportedPrimMask = (1 << GL_POINTS) |
660 (1 << GL_LINES) |
661 (1 << GL_LINE_LOOP) |
662 (1 << GL_LINE_STRIP) |
663 (1 << GL_TRIANGLES) |
664 (1 << GL_TRIANGLE_STRIP) |
665 (1 << GL_TRIANGLE_FAN);
666
667 if (_mesa_is_desktop_gl_compat(ctx)) {
668 ctx->SupportedPrimMask |= (1 << GL_QUADS) |
669 (1 << GL_QUAD_STRIP) |
670 (1 << GL_POLYGON);
671 }
672
673 if (_mesa_has_geometry_shaders(ctx)) {
674 ctx->SupportedPrimMask |= (1 << GL_LINES_ADJACENCY) |
675 (1 << GL_LINE_STRIP_ADJACENCY) |
676 (1 << GL_TRIANGLES_ADJACENCY) |
677 (1 << GL_TRIANGLE_STRIP_ADJACENCY);
678 }
679
680 if (_mesa_has_tessellation(ctx))
681 ctx->SupportedPrimMask |= 1 << GL_PATCHES;
682
683 /* Appendix F.2 of the OpenGL ES 3.0 spec says:
684 *
685 * "OpenGL ES 3.0 requires that all cube map filtering be
686 * seamless. OpenGL ES 2.0 specified that a single cube map face be
687 * selected and used for filtering."
688 *
689 * Now that we know our version, enable seamless filtering for GLES3 only.
690 */
691 ctx->Texture.CubeMapSeamless = _mesa_is_gles3(ctx);
692
693 /* First time initialization. */
694 _mesa_update_valid_to_render_state(ctx);
695 }
696
697
698 void
_mesa_get_driver_uuid(struct gl_context * ctx,GLint * uuid)699 _mesa_get_driver_uuid(struct gl_context *ctx, GLint *uuid)
700 {
701 struct pipe_screen *screen = ctx->pipe->screen;
702 assert(GL_UUID_SIZE_EXT >= PIPE_UUID_SIZE);
703 memset(uuid, 0, GL_UUID_SIZE_EXT);
704 screen->get_driver_uuid(screen, (char *)uuid);
705 }
706
707 void
_mesa_get_device_uuid(struct gl_context * ctx,GLint * uuid)708 _mesa_get_device_uuid(struct gl_context *ctx, GLint *uuid)
709 {
710 struct pipe_screen *screen = ctx->pipe->screen;
711 assert(GL_UUID_SIZE_EXT >= PIPE_UUID_SIZE);
712 memset(uuid, 0, GL_UUID_SIZE_EXT);
713 screen->get_device_uuid(screen, (char *)uuid);
714 }
715
716 void
_mesa_get_device_luid(struct gl_context * ctx,GLint * luid)717 _mesa_get_device_luid(struct gl_context *ctx, GLint *luid)
718 {
719 struct pipe_screen *screen = ctx->pipe->screen;
720 assert(GL_LUID_SIZE_EXT >= PIPE_LUID_SIZE);
721 memset(luid, 0, GL_UUID_SIZE_EXT);
722 screen->get_device_luid(screen, (char *)luid);
723 }
724
725 /**
726 * Get the i-th GLSL version string. If index=0, return the most recent
727 * supported version.
728 * \param ctx context to query
729 * \param index which version string to return, or -1 if none
730 * \param versionOut returns the vesrion string
731 * \return total number of shading language versions.
732 */
733 int
_mesa_get_shading_language_version(const struct gl_context * ctx,int index,char ** versionOut)734 _mesa_get_shading_language_version(const struct gl_context *ctx,
735 int index,
736 char **versionOut)
737 {
738 int n = 0;
739
740 #define GLSL_VERSION(S) \
741 if (n++ == index) \
742 *versionOut = S
743
744 /* GLSL core */
745 if (ctx->Const.GLSLVersion >= 460)
746 GLSL_VERSION("460");
747 if (ctx->Const.GLSLVersion >= 450)
748 GLSL_VERSION("450");
749 if (ctx->Const.GLSLVersion >= 440)
750 GLSL_VERSION("440");
751 if (ctx->Const.GLSLVersion >= 430)
752 GLSL_VERSION("430");
753 if (ctx->Const.GLSLVersion >= 420)
754 GLSL_VERSION("420");
755 if (ctx->Const.GLSLVersion >= 410)
756 GLSL_VERSION("410");
757 if (ctx->Const.GLSLVersion >= 400)
758 GLSL_VERSION("400");
759 if (ctx->Const.GLSLVersion >= 330)
760 GLSL_VERSION("330");
761 if (ctx->Const.GLSLVersion >= 150)
762 GLSL_VERSION("150");
763 if (ctx->Const.GLSLVersion >= 140)
764 GLSL_VERSION("140");
765 if (ctx->Const.GLSLVersion >= 130)
766 GLSL_VERSION("130");
767 if (ctx->Const.GLSLVersion >= 120)
768 GLSL_VERSION("120");
769 /* The GL spec says to return the empty string for GLSL 1.10 */
770 if (ctx->Const.GLSLVersion >= 110)
771 GLSL_VERSION("");
772
773 /* GLSL es */
774 if (_mesa_is_gles32_compatible(ctx))
775 GLSL_VERSION("320 es");
776 if (_mesa_is_gles31_compatible(ctx))
777 GLSL_VERSION("310 es");
778 if (_mesa_is_gles3_compatible(ctx))
779 GLSL_VERSION("300 es");
780 if (_mesa_is_gles2_compatible(ctx))
781 GLSL_VERSION("100");
782
783 #undef GLSL_VERSION
784
785 return n;
786 }
787